Email Address Validation for ASP.NET

前端 未结 8 850
梦如初夏
梦如初夏 2020-12-01 13:45

What do you use to validate an email address on a ASP.NET form. I want to make sure that it contains no XSS exploits.

This is ASP.NET 1.1

相关标签:
8条回答
  • 2020-12-01 14:20

    Any script tags posted on an ASP.NET web form will cause your site to throw and unhandled exception.

    You can use a asp regex validator to confirm input, just ensure you wrap your code behind method with a if(IsValid) clause in case your javascript is bypassed. If your client javascript is bypassed and script tags are posted to your asp.net form, asp.net will throw a unhandled exception.

    You can use something like:

    <asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
    
    0 讨论(0)
  • 2020-12-01 14:21

    In our code we have a specific validator inherited from the BaseValidator class.

    This class does the following:

    1. Validates the e-mail address against a regular expression.
    2. Does a lookup on the MX record for the domain to make sure there is at least a server to deliver to.

    This is the closest you can get to validation without actually sending the person an e-mail confirmation link.

    0 讨论(0)
提交回复
热议问题