tags:

views:

71

answers:

2

Note: question has been edited to stay in sync with what I have tried from the commenters

I am trying to match an email, however when put the same expression in the code behind, vs the aspx, I seem to be getting different matches for email address. The aspx regex validator seems to be working correctly, however I need to validate for my webservice as well. Im sure Im missing something simple here, does anyone have any ideas.

 Regex regExEmail = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); 
 if (!regExEmail.IsMatch(contact.emailAddress))
 {
     //do something
 }
+1  A: 

Use asp:CustomValidator instead of RegularExpressionValidator which will call any validation method from a library, the same as will be used by the WS.

abatishchev
+1  A: 

In your Regex constructor, you can use the two-parameter version to set the RegexOptions value. This enumeration includes a value for ECMAScript, which will cause the Regex matching to follow ECMAScript-compliant behavior.

JeremyDWill
This would help if the goal is to get a JavaScript regexp and ASP.NET regexp to work the same way, but I'm not sure how it helps here.
Steven Sudit
@Steven Sudit - I took the OP's question to mean that his rendered ASP.NET page (hence HTML/JavaScript) was using the specified regex, and he wanted his web service to use the same regex for validation. Setting the ECMAScript enum in the regex constructor used by the web service should accomplish this, correct?
JeremyDWill
Yes JeremyDWill, that is exactly what I was trying to say. I apologize if I did not word my question correctly
Kirit Chandran
You know, I think you're right.
Steven Sudit