By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,877 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,877 IT Pros & Developers. It's quick & easy.

regular expression validator, get rid of unwanted characters

P: n/a
Hi I have a regular expression validator for my username field which
just allows 3 to 30 characters without spaces to be inputted by the
user.

^\S{3,30}$

How can I add to this expression not to allow characters such as
"?/{]-.*'!" etc...?

Thank you.

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Steve" <ba****@iranmania.com> wrote in news:1126965826.140231.191620
@o13g2000cwo.googlegroups.com:
Hi I have a regular expression validator for my username field which
just allows 3 to 30 characters without spaces to be inputted by the
user.

^\S{3,30}$

How can I add to this expression not to allow characters such as
"?/{]-.*'!" etc...?

^[A-Za-z]{3,30}$

That should do it
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
Nov 19 '05 #2

P: n/a
Thank you Lucas for the help. I really want to learn how I can specify
which characters I do NOT want as opposed to what I want. Do you know
the syntax for this?

Nov 19 '05 #3

P: n/a
Steve,

Here's an excerpt from:

http://www.15seconds.com/issue/010301.htm (Where there are some great
regular expression examples given.)

A caret (^) at the begging of the pattern string enforces that the target
string should start with the pattern string. But if you put the caret inside
the square brackets [^], then it is altogether a different meaning. Caret
inside the square bracket means "don't match the characters inside the
brackets."
m[^ai]n --- matches men, mend, diamond

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Steve" <ba****@iranmania.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thank you Lucas for the help. I really want to learn how I can specify
which characters I do NOT want as opposed to what I want. Do you know
the syntax for this?

Nov 19 '05 #4

P: n/a
Thank you very much for your help. I'll check out that article as well.

Nov 19 '05 #5

P: n/a
Steve,

Anytime!

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Steve" <ba****@iranmania.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thank you very much for your help. I'll check out that article as well.

Nov 19 '05 #6

P: n/a
"Steve" <ba****@iranmania.com> wrote in news:1126971135.813362.284690
@g49g2000cwa.googlegroups.com:
Thank you Lucas for the help. I really want to learn how I can specify
which characters I do NOT want as opposed to what I want. Do you know
the syntax for this?


Just be aware if you go that route, you'll have to filter out a lot of
characters (i.e. numeric, non-ascii, symbols, etc). Basically there are a
lot of combinations you'll need to filter. If you insist on going this
route, you might want to look at Unicode Character sets. .NET's regular
expression parser has the ability to specific sets of characters with
shortcuts:

\p{name} Matches any character in the named character class specified by
{name}. Supported names are Unicode groups and block ranges. For example,
Ll, Nd, Z, IsGreek, IsBoxDrawing.

\P{name} Matches text not included in groups and block ranges specified in
{name}.

It might be best to stick with the KISS principle, and only allow a certain
character set : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
Nov 19 '05 #7

P: n/a
I think you are right. I did actually want to allow a unicode
characterset to be honest as you guessed. i.e. i want to allow
alphanumeric+ a unicode character set.

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.