Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!