RegularExpressionValidator : Syntax

J

Jennifer Mathews

For a RegularExpressionValidator I am using the following:

ErrorMessage="Department name length is between 3 & 20 characters and can alphanumeric, spaces, commas, periods or ?&#$%():;,._"
ValidationExpression="[?&#$%():;,._ 0-9a-zA-Z]{3,20}"

(Questionmark,Ampersand,pound,dollar,percent,(,),colon,semicolon,comma,period, and finally the underscore.)

It works fine.

Put I would like to include the "hyphen" character ( "-" ) and when I put it in after the "underscore" the validator crashes.

So the question is:
How can I include the "hyphen" as a valid character in the ValidationExpression?

Thanks
 
J

Jeff Johnson

For a RegularExpressionValidator I am using the following:
ErrorMessage="Department name length is between 3 & 20 characters and
can alphanumeric, spaces, commas, periods or ?&#$%():;,._"
ValidationExpression="[?&#$%():;,._ 0-9a-zA-Z]{3,20}"
(Questionmark,Ampersand,pound,dollar,percent,(,),colon,semicolon,comma,
period, and finally the underscore.)
It works fine.
Put I would like to include the "hyphen" character ( "-" ) and when I put
it in after
the "underscore" the validator crashes.
So the question is:
How can I include the "hyphen" as a valid character in the
ValidationExpression?

[Ick, HTML post!]

The dash character is special inside a character class (stuff in brackets
[ ] ) because, as you have already used it, it defines a range. To use it as
an actual character you must either escape it ( \- ) or put it at the very
beginning or very end of the list of characters.
 
J

Jennifer Mathews

That did the trick. Thanks

Jeff Johnson said:
For a RegularExpressionValidator I am using the following:
ErrorMessage="Department name length is between 3 & 20 characters and
can alphanumeric, spaces, commas, periods or ?&#$%():;,._"
ValidationExpression="[?&#$%():;,._ 0-9a-zA-Z]{3,20}"
(Questionmark,Ampersand,pound,dollar,percent,(,),colon,semicolon,comma,
period, and finally the underscore.)
It works fine.
Put I would like to include the "hyphen" character ( "-" ) and when I put it in after
the "underscore" the validator crashes.
So the question is:
How can I include the "hyphen" as a valid character in the ValidationExpression?

[Ick, HTML post!]

The dash character is special inside a character class (stuff in brackets [ ] )
because, as you have already used it, it defines a range. To use it as an actual
character you must either escape it ( \- ) or put it at the very beginning or very end
of the list of characters.
 

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

Top