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!

3 Answers 3

1

Try this:

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

Sign up to request clarification or add additional context in comments.

Comments

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)

1 Comment

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.
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.

1 Comment

Thank you, see my comment on Sachin Shanbhag's answer. I entered a simple example on purpose...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.