Need Help With Simple Regular Expression

J

Joey

Hello,

I need a regular expression that will allow alpha-numeric characters,
the underscore character, the period character, and the single quote
character.

The following is not working, for some reason...

[0-9a-zA-Z_.']

Can someone provide one that works?
 
K

Kevin Spencer

Perhaps you're missing a quantifier:

[0-9a-zA-Z_.']

will match a single character.

[0-9a-zA-Z_.']* (0 or more)
[0-9a-zA-Z_.']+ (1 or more)
[0-9a-zA-Z_.']{X} (Exactly X)
[0-9a-zA-Z_.'] {X, Z} (Between X and Z)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.
 
J

Joey

I have a textbox where I need to take input and limit the characters to
"0-9", "a-z", "A-Z", single quote, period, and underscore, and spaces.

I added a regular expression validator to my webpage, but it is not
working properly with the ValidationExpression property set to the
following...

[0-9a-zA-Z_.']+

I understand that I still may need to add something to get it to allow
spaces, but it won't even work without any spaces at this point. The
input will be from 1-15 characters.

What am I doing wrong?
 
K

Kevin Spencer

Post your IsValid code.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

If the truth hurts, wear it.

Joey said:
Any ideas, guys?
I have a textbox where I need to take input and limit the characters to
"0-9", "a-z", "A-Z", single quote, period, and underscore, and spaces.

I added a regular expression validator to my webpage, but it is not
working properly with the ValidationExpression property set to the
following...

[0-9a-zA-Z_.']+

I understand that I still may need to add something to get it to allow
spaces, but it won't even work without any spaces at this point. The
input will be from 1-15 characters.

What am I doing wrong?
 
K

Kevin Spencer

If that works for you, I would suggest the following instead:

[0-9a-zA-Z_'. ]+

This has a literal space at the end of the character class. "\s" indicates
that *any* whitespace character will match.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

If the truth hurts, wear it.
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top