can we use a regular expression to valid a stirng

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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

Oliver Sturm

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
 
O

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

regular expression 7
Regular expression 5
Regular expression 4
Regular Expression? 3
need some finer tuning on the regular expression 9
One more regular expression 4
Regex with time 3
Regular Expression Help 3

Top