RegularExpressionValidator显示以下字段不能为空的异常

时间:2012-12-24 18:09:39

标签: asp.net visual-studio-2010 validation

我有一个文本框txtemailid,其中包含两个验证程序RequiredFieldValidatorRegularExpressionValidator

<asp:TextBox ID="txtEMailId" CssClass="Text1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVtxtEMailId"
    runat="server"
    ErrorMessage="*"
    Display="Dynamic"
    ForeColor="Red"
    ControlToValidate="txtEMailId"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="REVtxtEMailId"
    runat="server"
    ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
    Display="Dynamic"
    ErrorMessage="Invalid Email Format"
    ForeColor="Red"></asp:RegularExpressionValidator>

它显示以下错误

The ControlToValidate property of 'REVtxtEMailId' cannot be blank.

2 个答案:

答案 0 :(得分:2)

您尚未指定应验证哪个控件。请尝试此

<asp:RegularExpressionValidator ID="REVtxtEMailId"
    runat="server"
    ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
    Display="Dynamic"
    ErrorMessage="Invalid Email Format"
    ForeColor="Red" ControlToValidate="txtEMailId"></asp:RegularExpressionValidator>

答案 1 :(得分:0)

您尚未在正则表达式Validator中提供ControlTo Validate属性。在REVtxtEMailId中添加此属性