Regular Expression question

B

Brian Simmons

Hi All,

I've got a textbox where I want to make sure the person has entered at least
3 characters before submitting (it's like a partial name lookup type of
query), so I don't want them to just enter "a" or "e" in the box and bring
back everyone with an "a" or "e" in their name.

I figure that a regular expression validation is the way to go, and I tried
this:
ValidationExpression="^([a-zA-z0-9\s]{3,255})$"

However, this doesn't work all the time, because a user can enter "dr." or
"st." and that is 3 characters but the validation fails, because the "." is
not recognized as a character.

So, can some kind soul help me out with the accurate regular expression for
what I want to accomplish?

Thanks,
Brian
 
G

Guest

Hi Brian,
Why a regular expression? I would just use "TextBox.Text..Length > 3".
If you really want a regualr expression, try ".{3,255}". The "." will
match anything (except newlines).
Ethan

Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
 
S

Sherif Elmetainy

ValidationExpression= ".{3,255}"

Btw the ^ and $ at the beginning and end of the expression are redundant in
RegularExpressionValidator since the validation code checks that the match
occurs at position zero and match length equals validated string length.
 
M

marss

Hi All,

I've got a textbox where I want to make sure the person has entered at least
3 characters before submitting (it's like a partial name lookup type of
query), so I don't want them to just enter "a" or "e" in the box and bring
back everyone with an "a" or "e" in their name.

I figure that a regular expression validation is the way to go, and I tried
this:
ValidationExpression="^([a-zA-z0-9\s]{3,255})$"

However, this doesn't work all the time, because a user can enter "dr." or
"st." and that is 3 characters but the validation fails, because the "." is
not recognized as a character.

So, can some kind soul help me out with the accurate regular expression for
what I want to accomplish?

Thanks,
Brian

If you want limit possible characters with letters, numbers and dot:
[a-zA-Z0-9\.]{3,}
It can be shorter [\w\.]{3,} but in that case it also allows
underscore.

Regards,
Mykola
http://marss.co.ua
 
J

Jesse Houwing

Hello Sherif,
ValidationExpression= ".{3,255}"

Btw the ^ and $ at the beginning and end of the expression are
redundant in RegularExpressionValidator since the validation code
checks that the match occurs at position zero and match length equals
validated string length.

You might also want to take alook at this article:
http://www.informit.com/articles/article.aspx?p=516589&seqNum=6&rl=1

It describes how to make a CustomValidator which will do a length check.
Should be quite simple to let it check both min and maxlength.


Hi All,

I've got a textbox where I want to make sure the person has entered
at least 3 characters before submitting (it's like a partial name
lookup type of query), so I don't want them to just enter "a" or "e"
in the box and bring back everyone with an "a" or "e" in their name.

I figure that a regular expression validation is the way to go, and I
tried this:
ValidationExpression="^([a-zA-z0-9\s]{3,255})$"
However, this doesn't work all the time, because a user can enter
"dr." or "st." and that is 3 characters but the validation fails,
because the "." is not recognized as a character.

So, can some kind soul help me out with the accurate regular
expression for what I want to accomplish?

Thanks,
Brian
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top