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 开发者_Go百科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
}
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.
Use asp:CustomValidator
instead of RegularExpressionValidator which will call any validation method from a library, the same as will be used by the WS.
精彩评论