jquery - Validate phone number by custom validator and javascript -


i have phonetextbox control, contains 4 textboxes:

country code (1-3 digits), city code (1-7 digits), local number (1-7 digits) , phone number (1-5 digits).

the phone number not required.

the code below doesn't work.

    <script type="text/javascript">     function validatephonenumber(source, args)       {         if (     $('#<%=txtcountrycode.clientid %>').val().match(/^\d{1,3}$) ||                  $('#<%=txtcitycode.clientid %>').val().match(/^\d{1,7}$) ||                  $('#<%=txtmainphonenumber.clientid %>').val().match(/^\d{1,7}$)            )           {             if ($('#<%=txtextraphonenumber.clientid %>').val().length<=0)             {                args.isvalid = true;                return;             }             else              {                 if ($('#<%=txtextraphonenumber.clientid %>').val().match(/^\d{1,5}$)                 {                     args.isvalid = true;                    return;                  }                 else                  {                     args.isvalid = false;                  }              }         }         else                  {                     args.isvalid = false;                  }  } </script>     <div style="display: inline">         <asp:customvalidator runat="server" forecolor="red" errormessage="invalid format" clientvalidationfunction="validatephonenumber" />         <div>             <b>+</b><asp:textbox id="txtcountrycode" runat="server" width="30px" maxlength="3"></asp:textbox>             <asp:textbox id="txtcitycode" runat="server" width="60px" maxlength="7"></asp:textbox>             <asp:textbox id="txtmainphonenumber" runat="server" width="60px" maxlength="7"></asp:textbox>             <asp:textbox id="txtextraphonenumber" runat="server" width="50px" maxlength="5"></asp:textbox>         </div>     </div> 

    args.isvalid = $('#<%=txtcountrycode.clientid %>').val().match(/^\d{1,3}$/) &&                  $('#<%=txtcitycode.clientid %>').val().match(/^\d{1,7}$/) &&                  $('#<%=txtmainphonenumber.clientid %>').val().match(/^\d{1,7}$/) && $('#<%=txtextraphonenumber.clientid %>').val().match(/^\d{0,5}$/); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -