regularexpressionvalidator验证控件使用实例
原文地址:regularexpressionvalidator验证控件使用实例作者:yishiontom
一:电话号码验证:
格式如:0755-24256888;带分机格式:0755-24256888-282;手机:11位数字
(^(d{3,4}-)?d{6,8}$)|(^(d{3,8}(-d{1,5})?$)|(d{11})
用法示例:
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="请注意格式"
ValidationExpression="(^(d{3,5})?$)|(d{11})"
ControlToValidate="txtPhone" Display="Dynamic">
</asp:RegularExpressionValidator>
二、关键字验证:
<asp:requiredFieldValidator
ID="requiredFieldValidator1" runat="server" ControlToValidate="keywords" Display="Dynamic"
ErrorMessage="请填写企业关键字!"></asp:requiredFieldValidator><asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server" ControlToValidate="keywords" ErrorMessage="关键字只能为汉字且字数不能超过4个!" ValidationExpression="^[u4e00-u9fa5]{1,4}$"></asp:RegularExpressionValidator>
三、电子邮箱验证:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Display="Dynamic" ErrorMessage="邮箱格式不正确" ControlToValidate="email" ValidationExpression="^[a-zA-Z0-9]{1,}@[a-zA-Z0-9]{1,}.(com|net|org|edu|mil|cn|cc)$"></asp:RegularExpressionValidator>
四、身份证号验证:
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="idcode"
ValidationExpression="^[1-9]([0-9]{16}|[0-9]{13})[xX0-9]$" Display="Dynamic">不是身份证号
</asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="revEMAIL" runat="server" ControlToValidate="txtEMAIL"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="电子邮件格式不对">
</asp:RegularExpressionValidator>
http://blog.163.com/soli1988_blog/blog/static/1768952722012616115119754/
原文链接:https://www.f2er.com/regex/362985.html