How do I shorten the length of my field and only allow numeric characters

Cupcake
Mega Guru

I have a field on a catalog form. The field is requesting the last four digits of the SSN # or Personal ID #. Today the field is setup as a single line text field, but I want to do the following:

a) make the field size = 4

b) I only want to allow that field to have numeric characters

find_real_file.png

I want to ensure that when I shorten the field size that I am only shortening it for this variable.

Thanks,

Karen

1 ACCEPTED SOLUTION

My apologies. Try changing it to /^[0-9][0-9][0-9][0-9]$/ inside the quotes.


View solution in original post

16 REPLIES 16

My apologies. Try changing it to /^[0-9][0-9][0-9][0-9]$/ inside the quotes.


Thank you so much, after I changed it - it works perfectly.


Hi Karen,



As to regex this should do: "^[0-9]{1,4}$"



By the way when you want to test your regexes try this website: Online regex tester and debugger: JavaScript, Python, PHP, and PCR


It also nicely explains what rules are applied on the right hand side.




Cheers



Greg


Greg, that won't require all four numbers to be provided. I believe that the PIN and SSN will always be 4 characters, which is why I gave her the expression I did.


Hi Joshua,



Ahh, yes you're right. We can shorten it to this then: "^\d{4}$" which is basically your response.




Cheers



Greg