user2018830
user2018830

Reputation: 11

Control to Validate not find the id

<input id="x_card_num" name="x_card_num" type="text" value="<%: CreditCardNumber %>"required="required" maxlength="16" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="x_card_num" ValidationExpression="/^[0-9]{16}/" ErrorMessage="invalid Card Number" ID="RegExCardnumber">
</asp:RegularExpressionValidator>

When I use this regular expression, I am getting the error:

controltoValidate id not found.

Upvotes: 1

Views: 120

Answers (1)

Win
Win

Reputation: 62290

Error message said it all. You need to assign ControlToValidate like this -

<asp:TextBox ID="EmailTextBox" runat="server" ... />
<asp:RegularExpressionValidator ControlToValidate="EmailTextBox" ... />

Update for last added code

If you want to validate regular HTML control, you need runat="server".

<input ... runat="server" />

Upvotes: 1

Related Questions