user3614070
user3614070

Reputation: 141

15-250 regex validation

I'm trying to build up some regular expressions to validate a textbox on c# wpf. I build the following to validate a number from 6 to 3600:

^([6-9]|[1-9][0-9]{1,2}|[12][0-9]{3}|3[0-5][0-9]{2}|3600)$ 

Now I need to validate from 15 to 250. I am new on regex and I am having a hard time getting it.

Thanks

Upvotes: 0

Views: 189

Answers (4)

Rahul Tripathi
Rahul Tripathi

Reputation: 172568

Here is a good read for Matching Numeric Ranges with a Regular Expression

The Regex for 15 to 250 would be

^(1[5-9]|[2-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|250)$

Regex Demo

Upvotes: 0

Guvante
Guvante

Reputation: 19223

A direct translation would be:

^(1[5-9]|[2-9][0-9]|1[0-9]{2}|2[0-4][0-9]|250)$

Split up it is 1[5-9] or 15-19, [2-9][0-9] or 20-99, 1[0-9]{2} or 200-199, 2[0-4][0-9] or 100-249, 250.

Upvotes: 2

dotNET
dotNET

Reputation: 35430

The following RegEx should satisfy all numbers in the range 15-250. However, as I have cautioned you in the comments, a NumericUpDown is a far superior choice for this kind of stuff:

\b(2[0-4]\d)|(1\d\d)|(250)|([2-9]\d)|(1[5-9])\b

Upvotes: 0

Marko
Marko

Reputation: 2734

You want the number validated from 6 - 3600 and another 15 - 250? why not just convert the number to int and check the min and max?

Take a look at the following to correctly implement validation in WPF https://msdn.microsoft.com/en-us/library/ms753962%28v=vs.110%29.aspx

Upvotes: 1

Related Questions