RegularExpressionValidator

J

Jason

Hi ,

I'm attempting to use the Regular Expression Validator to cehck for
the following conditions:

<sequence of letters><sequence of numbers>
or
<sequence of letters><sequence of numbers> \ <sequence of numbers>
or
<sequence of letters><sequence of numbers> \ <sequence of numbers> \
<sequence of numbers>

the first condition is obviously easy, I can put [a-z|A-Z]+[0-9]+ and
it works fine, my problem occurs when trying to get the validator to
check for a literal backslash. I've checked many articles on this now
and all say the method I've been using ( i.e. using \\ or \\\\) should
work but it very clearly does not! Anyone know what the correct use
is? I've been setting this in the ValidationExpression property of the
control.
 
N

Nathan Sokalski

Try this:

ValidationExpression="[a-zA-Z]*\d*(\\\d*){0,2}"

The first part

[a-zA-Z]*\d*

takes care of the <sequence of letters><sequence of numbers> section by
allowing 0 or more letters followed by 0 or more numbers. The next part

(\\\d*){0,2}

takes care of the \ <sequence of numbers> sections. What this code does is
it groups the \ and the <sequence of numbers> together, and then says you
can use from 0 to 2 of these. for more information, see the following
documentation pages:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/36b81212-6511-49ed-a8f1-ff080415312f.htm
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/0f8bffab-ee0d-4e0e-9a96-2b4a252bb7e4.htm

I think your problem was that you were looking at the documentation pages
for the Regex object, which is slightly different than the
RegularExpressionValidator. If you need any more help with this, let me
know. Good Luck!
 
J

Jason

Thanks Nathan, worked brilliantly and yes you were right, I was
looking at the wrong documentation.

Try this:

ValidationExpression="[a-zA-Z]*\d*(\\\d*){0,2}"

The first part

[a-zA-Z]*\d*

takes care of the <sequence of letters><sequence of numbers> section by
allowing 0 or more letters followed by 0 or more numbers. The next part

(\\\d*){0,2}

takes care of the \ <sequence of numbers> sections. What this code does is
it groups the \ and the <sequence of numbers> together, and then says you
can use from 0 to 2 of these. for more information, see the following
documentation pages:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/36b­81212-6511-49ed-a8f1-ff080415312f.htm
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/0f8­bffab-ee0d-4e0e-9a96-2b4a252bb7e4.htm

I think your problem was that you were looking at the documentation pages
for the Regex object, which is slightly different than the
RegularExpressionValidator. If you need any more help with this, let me
know. Good Luck!
--
Nathan Sokalski
(e-mail address removed)://www.nathansokalski.com/




I'm attempting to use the Regular Expression Validator to cehck for
the following conditions:
<sequence of letters><sequence of numbers>
or
<sequence of letters><sequence of numbers> \ <sequence of numbers>
or
<sequence of letters><sequence of numbers> \ <sequence of numbers> \
<sequence of numbers>
the first condition is obviously easy, I can put [a-z|A-Z]+[0-9]+ and
it works fine, my problem occurs when trying to get the validator to
check for a literal backslash. I've checked many articles on this now
and all say the method I've been using ( i.e. using \\ or \\\\) should
work but it very clearly does not! Anyone know what the correct use
is? I've been setting this in the ValidationExpression property of the
control.- Hide quoted text -

- Show quoted text -
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top