ASP.NET 的电子邮件地址验证 [英] Email Address Validation for ASP.NET

查看:33
本文介绍了ASP.NET 的电子邮件地址验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您使用什么来验证 ASP.NET 表单上的电子邮件地址.我想确保它不包含 XSS 漏洞.

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.

这是 ASP.NET 1.1

This is ASP.NET 1.1

推荐答案

发布在 ASP.NET Web 表单上的任何脚本标记都会导致您的网站抛出和未处理的异常.

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

您可以使用 asp 正则表达式验证器来确认输入,只需确保使用 if(IsValid) 子句将代码隐藏在方法后面,以防您的 javascript 被绕过.如果您的客户端 javascript 被绕过并且脚本标签被发布到您的 asp.net 表单,asp.net 将抛出一个未处理的异常.

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.

您可以使用以下内容:

<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>

这篇关于ASP.NET 的电子邮件地址验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆