When a user submits a form I need to make sure that the input contains at least a minimum number of digits. The problem is that I don’t know what format the input will be in. The digits likely won’t be in a row, and might be separated by letters, punctuation, spaces, etc. I don’t care about the rest of the string.
I’d like to check this with a RegularExpressionValidator but I’m not quite sure how to write the regex.
I guess this would be similar to a phone number regex, but a phone number at least has some common formats.
The following will match an input string containing at least
ndigits:where
nis an integer value.A short explanation:
\D*matches zero or more non-digit chars (\Dis a short hand for[^0-9]or[^\d]);\D*\dmatches zero or more non-digit chars followed by a digit;(\D*\d){n}groups, and repeats, the previousntimes.