Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want regular expression to accept 1 - 9 numeric digits.May not be in the ranges-0090000000 - 009499999,0900000000 - 094000000


I have tired but its not working "^([^0900000000-009499999]|[^0900000000-094000000]|\d{9}|\d{1}|\d{2}|\d{3}|\d{4}|\d{5}|\d{6}|\d{7}|\d{8})$"


Please help me asap.



Regards,
Vijay
Posted

1 solution

Don't do range validation with a regex - that's really a code based system, while Regexes are text processors. You can do it, but it really is rather nasty and complex, and it's a real PITA to maintain if you need changes.
Do you primary validation with a Regex by all means to ensure that the value entered is all numeric and has the right number of digits - that's trivial - but do the actual value checking by converting the strings to numbers and checking them in your C# code. It's quicker, easier to understand, and a lot simpler to maintain in future.

Personally? I'd ignore the regex completely and use int.TryParse to convert the value. Then I'd range check it if it's a valid number.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900