can we use a regular expression to valid a stirng

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

We can use RegularExpressionValidator to valid the input of TextBox.
Can we use RegularExpression to valid a string in run time?
Like I have a regular expression "\d{3}"
Can I use this regular expression to determinate of a string is composited
of tree digital?
 
ad,

I think that using a regular expression, this is only going to find
matches in the string for that pattern. So if you have a longer string
which has something that matches that pattern, then it might still return a
match.

You should probably check the length of the string first, then run the
regular expression on it.

Hope this helps.
 
ad said:
We can use RegularExpressionValidator to valid the input of TextBox.
Can we use RegularExpression to valid a string in run time?
Like I have a regular expression "\d{3}"
Can I use this regular expression to determinate of a string is composited
of tree digital?

Sure, see my post on your thread "How to determinatel if a string is a
number".



Oliver Sturm
 
Nicholas said:
I think that using a regular expression, this is only going to find
matches in the string for that pattern. So if you have a longer string
which has something that matches that pattern, then it might still return a
match.

You should probably check the length of the string first, then run the
regular expression on it.

That's correct for the expression "\d{3}", because it doesn't have any
start or end markers. But no need to do the check for the length
separately, just insert the markers ^ (for start) and $ (for end):
"^\d{3}$".



Oliver Sturm
 
Back
Top