JavaScript function for field validation

I would like to validate a field against this JavaScript function:

I’m guessing I would be specifying "validator_calc": "luhnChk(model.thefield)"

But where do I put the luhnChk function?

You’ll need to use a function action to run some JavaScript and attach that function to the window. Put that action in either onFormLoad or onAppLoad depending on whether or not you need this on multiple pages. Then just add the following code after the function is defined:

window.luhnChk = luhnChk
1 Like

I think there is also a credit card validator type already, see here:

1 Like

The built in validator doesn’t seem to work - it must be checking for length or something additional beyond Luhn check digit. I’m trying to validate a SIN or BN (Canada).

Did you also set "validator": "calc" in addition to "validator_calc": "..."

Yes, everything works with your suggestion - that’s why I marked it as the solution. I was just responding to @delfs about why I couldn’t use the built in validator.

Thank you!