i have a text box that i enter a range to in a string format, the text in the text box is something like
“1 to 30”
“4 to 75”
so its integer &” to “& integer.
what is the best way to validate this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is a perfect task for regular expressions. In your case, the expression is as easy as
Which means:
^),\dis a digit, the following+means: one or more of the previous),\sis spaces, tabs etc.),to,$).In VB, you’d match it as follows:
This requires importing the
System.Text.RegularExpressionsnamespace.Regular expressions are an own language to describe strings, so they take a bit getting used to. But they are by far the easiest tool to handle such string validations and simple parsing jobs so learning them is obligatory.