RegularExpressionValidator : Syntax

  • Thread starter Thread starter Jennifer Mathews
  • Start date Start date
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
 
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.
 
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.
 
Back
Top