0

I've always been using Regex to check for user's input validity, ie checking for a correct mail adress, serial number, etc...

Now I want to check that the user input is, let's say, a number contained between : 78 and 143.

We're not quite analysing the user's input, but interpreting it and analysing after...

Would the Regex still be useful ? Would it be a good practice to use Regexs in that case ?

What would be the best way to control that kind of input ?

Thanks for your advices!

Andy M
  • 5,945
  • 7
  • 51
  • 96

3 Answers3

1

Try this:

http://www.regular-expressions.info/numericranges.html

Przemysław Michalski
  • 9,627
  • 7
  • 31
  • 37
1

I dont think regex is useful in this case. You can just use normal > and < operators for your cause.

Probably if you get this validation on client side, that will just be good too (unless your case is user-specific and needs server side validation)

Sachin Shanbhag
  • 54,530
  • 11
  • 89
  • 103
  • Actually, It's just a simple example of the different cases I have to solve... Of course I could simply use that, but the entries will be much more complicated than 78 or 143. – Andy M Nov 19 '10 at 12:30
0

Maybe you need the RangeValidator instead of the RegularExpressionValidator. The Regex adds complexity to a simple problem, so it's less useful, and therefore, not the best practice.

Les
  • 10,335
  • 4
  • 40
  • 60
  • Thank you, see my comment on Sachin Shanbhag's answer. I entered a simple example on purpose... – Andy M Nov 19 '10 at 12:33