javascript - Call to a java script function Regular Expression Validator to fail In asp.Net -


i have <asp:regularexpressionvalidator> validates text box have javascript function prevents entering of non numerical values in textbox. when use expression validator works fine add onkeydown="return jsdecimals(event);" text box call jsdecimals() function validator doesn't work. doing wrong??

asp code

<asp:textbox id="textbox2" runat="server" cssclass="form-control" causesvalidation="true" maxlength="13" onkeydown="return jsdecimals(event);"></asp:textbox>   <asp:button id="button5" runat="server" text="retrieve" cssclass="btn btn-default" onclick="button5_click"/>  <asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server" cssclass="tooltip-arrow"       errormessage="id must 13 numeric characters" controltovalidate="textbox2" validationexpression="^[0-9]{13}$"> </asp:regularexpressionvalidator> 

javascript:

function jsdecimals(e) {  var evt = (e) ? e : window.event; var key = (evt.keycode) ? evt.keycode : evt.which; if (key != null) {     key = parseint(key, 10);     if ((key < 48 || key > 57) && (key < 96 || key > 105)) {         if (!jsisuserfriendlychar(key, "decimals")) {             return false;         }     }     else {         if (evt.shiftkey) {             return false;         }     } } return true; function jsisuserfriendlychar(val, step) { // backspace, tab, enter, insert, , delete   if (val == 8 || val == 9 || val == 13 || val == 45 || val == 46) {     return true; } // ctrl, alt, capslock, home, end, , arrows   if ((val > 16 && val < 21) || (val > 34 && val < 41)) {     return true; } if (step == "decimals") {     if (val == 190 || val == 110) {  //check dot key code should allowed         return true;     } } // rest   return false; } 

your syntax incorrect. check comment on code below. not appear closing function after return true; , ending declaring next function within 1st one.

function jsdecimals(e) {    var evt = (e) ? e : window.event;   var key = (evt.keycode) ? evt.keycode : evt.which;   if (key != null) {     key = parseint(key, 10);     if ((key < 48 || key > 57) && (key < 96 || key > 105)) {       if (!jsisuserfriendlychar(key, "decimals")) {         return false;       }     } else {       if (evt.shiftkey) {         return false;       }     }   }   return true; // <-- what's this? there supposed closing bracket after line?    function jsisuserfriendlychar(val, step) {   .   .   . 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -