Isaac Johnson
asked on
How do I validate a asp.net field using javascript and pattern matching
I am trying to validate the presence and pattern of a field defined in an asp. net page.
The presence of the field works but when I enter the telephone number in the
field for pattern matching, it does not work. I get the error message.
Please advise,
Isaac
The presence of the field works but when I enter the telephone number in the
field for pattern matching, it does not work. I get the error message.
Please advise,
Isaac
<div visible="true" id="divTelephoneNumber" runat="server">
<div class="col-xs-12 col-md-8 col-sm-10 col-lg-6 nill">
<asp:Label ID="lblTelephoneNumber" runat="server" AssociatedControlID="txtTelephoneNumber" Text="Telephone number *" CssClass="control-label" />
<br />
<asp:TextBox ID="txtTelephoneNumber" runat="server" CssClass="form-control" MaxLength="20" aria-label="Telephone number" ></asp:TextBox>
<span class="required"></span>
<asp:CustomValidator id="rfVTN" runat="server" ControlToValidate="txtTelephoneNumber" ValidateEmptyText="true" ErrorMessage="Telephone Number is a required field. nnn-nnn-nnnn " ClientValidationFunction="ValidateTelephone"/>
</div>
</div>
<script type="text/javascript">
function ValidateTelephone(sender, args) {
var compare = RegExp("/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/");
args.IsValid = compare.test(args.Value);
return;
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again.
Isaac
Isaac
ASKER
Thanks for the tip.