'CustomValidator ASP.NET not throwing any error but not working as well
I am trying to write a validation that will add dash to number that users are entering in a textbox. But its not working can anyone guide what am I doing wrong here -
<script type = "text/javascript">
document.getElementById("<%=TXTNUM.ClientID %>").onkeypress = function myFun(e){
var keycodes = new Array(0,48,49,50,51,52,53,54,55,56,57);
var was = false;
for(x in keycodes){
if(keycodes[x] == e.charCode){
was = true;
break;
}
else{
was = false;
};
};
var val = this.value;
if(was === true){
switch(val.length){
case 3:
if(e.charCode !== 0){
this.value += "-";
}
break;
case 6:
if(e.charCode !== 0){
this.value += "-";
}
break;
default:
if(val.length > 10 && e.charCode !== 0){return false;};
break;
};
val += e.charCode;
}
else{
return false;
};
};
Below is customvalidator that I am trying to write
<asp:TextBox ID="TXTNUM" runat="server" Width="111px"></asp:TextBox>
<asp:CustomValidator ID="CustomeValidator19" runat="server" ControlToValidate="TXTNUM" clientValidationFunction = "myFun"> </asp:CustomValidator>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator15" runat="server" ControlToValidate="TXTNUM" CssClass="ErrorText"
Display="Dynamic" ErrorMessage="* Required" ForeColor=""></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TXTNUM"
CssClass="ErrorText" Display="Dynamic" ErrorMessage="* Invalid: Use Format 123-45-6789"
ForeColor="White" ValidationExpression="\d{3}-\d{2}-\d{4}"></asp:RegularExpressionValidator></td>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
