Click here to Skip to main content
15,894,252 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi
I need a regular expression to validate a textbox to enter only numbers from 1 to 24 with comma separated. Please help me.
Posted

1 solution

([1-9]|1[0-9]|2[0-4])(,([1-9]|1[0-9]|2[0-4]))*[^]
To break it down...

[1-9]|1[0-9]|2[0-4] This block is representing a numeric range from 1 to 24...Consider that regex is working with text, with character and know nothing of numbers, so you have to create character map that behaves like a numeric filter...
The second part is actually the same, but there is a preceding comma to separate the numbers...
 
Share this answer
 
Comments
SanSkun 24-Dec-15 0:50am    
Hi peter,
I need the regular expression for number from 1 to 24 validation. Its accepting more than 24 and 20 and 10 also not accepting

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