I want to validate that a text box contains only numbers between 0 and 10.
This is the regex I am currently using:
@"^([0-9]|10)"
But it only matches 0-9. What should I change to make it match 10??
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
1from10is matched by[0-9]because the regex engine matches from left to right. And since you only anchored the beginning-of-input :^, the engine is satisfied if the1is matched.There are two solutions.
1 – Swap it:
or
2 – anchor it with
$: