1

我正在尝试这样做:

<obout:OboutTextBox ID="txtDistributorEmail" runat="server" Width="250" />
    <asp:RegularExpressionValidator ID="revDistributorEmail" runat="server"     
    ErrorMessage="An invalid email address was entered."                                 
    ValidationExpression='<%=Mynamespace.RegEx.EMAIL %>' 
    ControlToValidate="txtDistributorEmail" />

namespace Mynamespace
{
    public class RegEx
    {
        public const string EMAIL = @"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z] 
        [-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
    }
 }

即使输入了正确的电子邮件,验证也会失败。但是如果我用ValidationExpression正则表达式替换[]它,它就可以正常工作。

有什么不正确的吗?

4

2 回答 2

0

试试这个;用于动态re验证。

RegularExpressionValidator re = new RegularExpressionValidator();
re.ControlToValidate = "textbox121"; //mention your textbox id
re.Style.Add("color", "Red");
re.ID = "Reg1";
re.ValidationExpression = "^[a-zA-Z\\s]+$";
re.ErrorMessage = "Special Characters Are Not Allowed";
于 2014-11-10T05:24:39.127 回答
0

这在 aspx 页面的顶部:

<%@ Import Namespace="Mynamespace" %>  

<asp:RegularExpressionValidator ID="revDistributorEmail" runat="server"     
    ErrorMessage="An invalid email address was entered."                                 
    ValidationExpression="<%# Mynamespace.RegEx.EMAIL %>" 
    Display="Dynamic"
    ControlToValidate="txtDistributorEmail" />
于 2012-09-14T20:23:43.660 回答