RegularExpressionValidator - how to detect strings you dont want?

G

Guest

Hi,

I am setting up RegularExpressionValidators for my form elements and found
no way of doing the following:

1) to validate so that Textbox.text does not contain certain phrases. e.g.
I don't want user to enter any of the following phrases (regex syntax):

(asp|php|zip)

2) to validate so that Textbox.text is not numeric (must have at least one
non-numeric characters)

I tried:

\D+

and it doesn't work
 
D

Damien

Hi,

I am setting up RegularExpressionValidators for my form elements and found
no way of doing the following:

1) to validate so that Textbox.text does not contain certain phrases. e.g.
I don't want user to enter any of the following phrases (regex syntax):

(asp|php|zip)

Regular expressions are very good for finding strings you're
interested in, not so good for excluding strings you don't want. I
can't think of an easy way of doing the above (I can think of a
horrendous one such as (([b-o]|[q-y]).*) being the first alternative,
then alternatives starting with a which aren't followed by an s, then
as followed by not p, etc).

*Especially* with file names (extensions), you are better off with
listing those file names which you consider good, rather than trying
to ban all of the possible file names which might be bad, since the
"bad" filename list is far more likely to change than and "good"
filename list. If all you want people to be able to use is, for
instance, txt, rtf, gif, jpg and png, then just let them use those.
2) to validate so that Textbox.text is not numeric (must have at least one
non-numeric characters)

I tried:

\D+

and it doesn't work

The above will match strings of all non-numeric characters. If you
want a string the must contain at least one non-numeric character,
then try .*\D.* (that is, any characters, followed by a non-numeric
character, followed by any characters).

Damien
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top