I have ValidationRegularExpression="[0-9]"
which only allows a single character. How do I make it allow between (and including) 1 and 7 digits? I tried [0-9]{1-7}
but it didn't work.
When simple regular expression syntax is being used, most characters, except metacharacters are treated as literal characters and match only themselves (for example, "a" matches "a", "(bc" matches "(bc", etc). Operators. Operator.
The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.
To check for all numbers in a field To get a string contains only numbers (0-9) we use a regular expression (/^[0-9]+$/) which allows only numbers. Next, the match() method of the string object is used to match the said regular expression against the input value.
You got the syntax almost correct: [0-9]{1,7}
.
You can make your solution a bit more elegant (and culture-sensitive) by replacing [0-9]
with the generic character group "decimal digit": \d
(remember that other languages might use different characters for digits than 0-9).
And here's the documentation for future reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With