Reputation: 46641
What is the regular expression to match the numbers 0 through 60? No negative numbers allowed and no decimals.
Upvotes: 1
Views: 4548
Reputation: 887797
Like this: ^([0-5]?[0-9]|60)$
In C#:
int temp;
if (int.TryParse(str, out temp) && temp >= 0 && temp <= 60)
Upvotes: 7
Reputation: 38130
Assuming Perl compatible regular expressions, and no leading zeroes
/([1-5]?[0-9]|60)/
Upvotes: 5