Xaisoft
Xaisoft

Reputation: 46641

Match 0 to 60 in regular expression

What is the regular expression to match the numbers 0 through 60? No negative numbers allowed and no decimals.

Upvotes: 1

Views: 4548

Answers (2)

SLaks
SLaks

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

Rowland Shaw
Rowland Shaw

Reputation: 38130

Assuming Perl compatible regular expressions, and no leading zeroes

/([1-5]?[0-9]|60)/

Upvotes: 5

Related Questions