开发者

How to validate the mail in the server side

How to validate Email in server side . I know how to do that in client side but what about the ser开发者_JS百科ver side?


You can try this.

 String mail = "YYY@imail.com";
 string expression = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" +@"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" +@"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

            Match match = Regex.Match(mail, expression, RegexOptions.IgnoreCase);
            if (match.Success)
                Response.Write("VALID EMAIL");
                else
                 Response.Write("INVALID EMAIL");
            return;


You could use a RegularExpressionValidator:

<asp:RegularExpressionValidator
        id="regEmail"
        ControlToValidate="txtEmail"
        Text="(Invalid email)"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        Runat="server" /> 

As far as the regular expression to use, just pick one that suits your needs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜