Checking numbers input with Regex - C#
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 ?
开发者_如何学JAVAWhat would be the best way to control that kind of input ?
Thanks for your advices!
Try this:
http://www.regular-expressions.info/numericranges.html
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)
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.
精彩评论