I have a ‘PIN’ number field I want to require 4 or 5 digits. Using the Add Pattern Validation box for the input box I put in the following RegEx: ^[0-9]{4,5}$
This fails to reject (red box) if I enter any valid number in the field. If I change the field to a TEXT input it works. Not really an issue since the RegEx forces only numerals but do regex pattern validations work on Number fields? If not, why prompt for it when it does nothing?
You can find out more about it here.
https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel
However, your code looks okay as for a number between 4 and 6 it should be this - {4,6}$ - and that can be shortened to just - ^\d{4,6}$ - if Wix accept it shortened.
Also, have a look at this site here as it might help you out if you are planning on doing a lot of Regex work.
https://regex101.com/
You will see that ^\d{4,5}$ and {4,5}$ works fine there and should be okay.
Thanks… I re-read: https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel and it indicates one can use pattern validation on number fields…but the regex that works for a text field does not work for a number field. Just a bug?
Yes you can use pattern as well as minimum and maximum like you have setup, so there is no reason why it shouldn’t work in your number input as long as the user is just adding numbers as the user input will check if it is a number, as it states in the validation field in the page linked before.
When you use the text input you should be using something like this from the example on that page linked before - ^[a-zA-Z0-9_]{5,20}$ - however for the number input it should just simply be ^[0-9]{4,5}$ like you have already done.
I have just tested it myself here on this test site here.
https://givemeawhisky.wixsite.com/numbervalidation
The left side of the example is with just the pattern regex of {4,5}$ and the maximum and minimum turned off in the user input settings for the number field.
This left side does seem to have the error that you have mentioned and the regex is not working.
The right side of the example is with no pattern regex and just the maximum set to 99999 and the minimum set to 1111.
This right side is working and you can only add numbers between 1111 and 99999.
So, looks like you will have to just use the minimum and the maximum options in the input settings instead of the regex pattern for the number input for the time being until we can see if this is just a bug or if it is the intended way of working, although it would go against the wording of the support page as it states that you can use both patterns and min and max.