Sometimes you may have a set of data which always has the same number of characters.
For example a UK landline telephone number has 11 characters.
A length check could be set up to ensure that exactly 11 numbers are entered into the field. This type of validation can't check that the 11 numbers are correct but it can ensure that 10 or 12 numbers aren't entered.
NET validation server control that ensures the number of characters entered and the RegularExpressionValidator can be used to check that a value may require that the number of characters not exceed a certain length.
You can use RegularExpressionValidator for accepting only four digits and RequiredFieldValidator for mandatory checking.Check the below example :
For example a UK landline telephone number has 11 characters.
A length check could be set up to ensure that exactly 11 numbers are entered into the field. This type of validation can't check that the 11 numbers are correct but it can ensure that 10 or 12 numbers aren't entered.
NET validation server control that ensures the number of characters entered and the RegularExpressionValidator can be used to check that a value may require that the number of characters not exceed a certain length.
You can use RegularExpressionValidator for accepting only four digits and RequiredFieldValidator for mandatory checking.Check the below example :
<asp:TextBox ID="txtPinCode"
runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regExpPinCode" runat="server" ControlToValidate="txtPinCode" ErrorMessage="Must be at least 4 digits" ValidationExpression="\d{11}">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqFieldPinCode" runat="server" ControlToValidate="txtPinCode" ErrorMessage="Post Code must be entered">
</asp:RequiredFieldValidator>