Skip to main content
Inspiring
May 5, 2019
Answered

Help with implementing restrictions to required numeric fields on a form

  • May 5, 2019
  • 1 reply
  • 2043 views

Hi,

I need some help with putting restrictions on two fields - a policy # and a loan #. They'll both be numeric only in any variety of combination, policy # containing only 13 digits, while the loan # has no limit. I want both fields to allow only numeric characters, and prompt a warning message if they're not filled out correctly. I attempted some script to do this but it didn't go well Any help is greatly appreciated!

Thanks,

Valerie

This topic has been closed for replies.
Correct answer try67

Hmm. So it's set a character of limit of 13 (yay), no alpha (yay again), but when I press tab to proceed to the next field, the numbers I entered are removed, and then to move onto another field I must press tab again. No alert pops up about 13 digits, and the numbers just disappear. I must be doing something wrong? I did the prior custom keystroke script, limit of 13, and added your new validation script...


Are you entering a 13-digit value? If so, it should work.

And no, I didn't add an error message, but that can be easily done, by adding this line to the end of the validation script:

if (!event.rc) app.alert("Error! You must enter a 13-digit number.");

1 reply

try67
Braniac
May 5, 2019

Do you want to limit what the user can enter, or to validate the value when they exit the field, and only allow it if it adheres to these rules?

Inspiring
May 5, 2019

I want to limit each field to numeric characters, with the policy# only allowing 13 digits, no more no less. Because both the policy and loan number can be any combination of numbers, I don't know how we could introduce validation, but then again i only know the very basics of creating forms; these validating things are not my cup of tea. The loan number shouldn't be limited to any certain number of characters. Thanks!

try67
Braniac
May 11, 2019

Hi, yeah, 13 and only 13, sorry about that. And I'm not sure what I'm doing wrong, but I put that in a custom keystroke script, a custom format script, took out the comb of characters, put it back in, etc. and couldn't make it work with what I need. When it's in the keystroke, I'm only able to put in 1 number, when it's in format, I can type in infinity. Not sure what I'm doing wrong... Thanks for continuing to help me! It's just without validating or confirming that an entry of exactly 13 numbers has been inputted, the form isn't really helpful to the dept. I'm doing it for.


My bad, use this code as the custom validation script:

if (event.value) event.rc = /^\d{13}$/.test(event.value);

And go back to the previous version of the Keystroke code, with the limit set to 13.