开发者

Regular expression behaving different on in c# code behind and on aspx

开发者 https://www.devze.com 2023-01-22 10:26 出处:网络
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 t

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消