IE7 having problems with regular expressions

T

tshad

Some of my regular expressions don't seem to work correctly in IE7. I am on
asp.net 1.1.

I have a site that has been up for a while and I started having problems on
machines with IE7. IE5 and IE6 seem to work fine.

In the following - 919-111-2222 as well as (919)111-2222 was giving one of
my clients the error message and IsValidate was set to false.

<asp:RegularExpressionValidator runat="server"
ErrorMessage=" Phone not in standard format"
Display="Dynamic"
ControlToValidate="Phone"
ValidationExpression="^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[-
..]?\d{3}[- .]?\d{4}$" />

In the following, (e-mail address removed) gave him an error.

<asp:RegularExpressionValidator
ControlToValidate="email"
Display="Dynamic"
Text = "<br> Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}"
runat="server" />

These worked fin on IE5 and IE6 as well as Mozilla and Firefox.

I am getting the error when leaving the field so I assume it has something
to do with MS' javascript code.

Is this a known problem or do I need to do something to make this work
correctly?

Thanks,

Tom
 
K

Kevin Spencer

The first thing that pops out at me is the email address of the client,
which is an AOL email address. This indicates that in all likelyhood the
user is not skilled with computers.

The second thing is the 2 anchors, one at the beginning, and one at the end,
indicating that the match must begin at the start of the string, and end at
the end of the string. Therefore,

"919-111-2222" and "(919)111-2222" will match, but
" 919-111-2222" and "(919)111-2222 " will not match, since they have spaces
either at the beginning or at the end. Neither will
"\n919-111-2222" and "(919)111-2222\n" because they have newline characters
at the beginning or at the end.

It might be safer and less trouble for you to omit these characters, or
perhaps replace them with white-space character classes, as in:

\s*[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[-.]?\d{3}[- .]?\d{4}\s*

This indicates that 0 or more white space characters may precede or follow
the value. You can always trim them on the server.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top