Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, I have an IE7 spesific REGEX problem.
I'm validating Email Address with the following regex:
^\s*[a-zA-Z0-9_\+-]{1,63}(\.[a-zA-Z0-9_\+-]{1,63})*@(?=[a-zA-Z0-9-\.]{0,255}\.?\s*$)[a-zA-Z0-9-]{1,63}(\.[a-zA-Z0-9-]{1,63}){0,126}\.([a-zA-Z]{2,63})\.?\s*$


This works every modern browser but IE7 (which support customer wants to extend to the page) does not work with f.e fistname.surname@domainname.com

I read about lookahead like "?=" being problem in IE7 but suggested changes do not seem to work? Does any regex guru has any ideas how to get this work with IE 7 and still keep it functional in more modern browser versions.
Posted
Comments
OriginalGriff 23-Sep-11 6:24am    
Do you mean that this regex fails in Javascript on IE7 only, but works on FF, Chrome,...?

How about visiting www.regexlib.com[^] and looking at some of the other email validation expressions

There are 38 listed under 'Email' tag.
 
Share this answer
 
try this
C#
public static bool emailid(string em)
       {
           const string MatchEmailPattern =
             @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
      + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
               [0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
      + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
               [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
      + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";



           if (!Regex.IsMatch(em, MatchEmailPattern))
               return true;
           else
               return false;

       }
 
Share this answer
 
Solution 2 seemed to work older IE:s

This was maybe the problem with previous regex:
}@(?=[a-zA-Z0-9-\.]{0,255}\.?\s*$)[
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900