html - How to use regex to validate a text box in jquery? -
This question seems to be repeated to someone but it is not. This script was working perfectly well, till this morning, but it now works oddly. I have tried several suggested ways to change the code, such as removing the second part and if! = "True" but if there is no luck, check the situation.
jquery HTML This is working in a Jsfiddle try
$ ("# controlButton"). Click (function () {var SHPname = $ ("# fname") Val (); var textfieldmask = /^[az\.ss-] {2,} $ /; /// Check full name if (SHPname. Length {0} {var testname = textfieldmask.test (SHPname); warning (testname); if (testname == "true") {var tstnm = "ok"; alert (tstnm);} other {warnings (" Enter the full name! "); $ ('# Fname'). (); False return;}} {Alert (" Please enter a name "); $ ('# fname'). Focus (); Back; }});
& lt; Label class = "required" = "name" title = "enter your name" & gt; & Lt; Input type = "text" id = "fname" name = "fname" /> receiver's name & lt; / Label & gt; & Lt; Label = "formsubmit" class = "nocontent" & gt; & Lt; An id = "controlButton" href = "#" class = "progress-button" & gt; & Lt; P id = "btntxt" & gt; Save & lt; / P & gt; & Lt; Img id = "loadergif" src = "../images/loader-cart.gif" width = "30" height = "14" alt = "" /> & Lt; / A & gt; & Lt; Strong> Note: & lt; / Strong> Item marked & lt; Img src = "picture / required gif" alt = "required marker" width = "12" height = "12" /> Required fields are & lt; / Label & gt; The strange part is that the first warning I have is "true", but the code runs! = "True" and enter alerts full name! Why is this happening? Please help me in it.
testname == true Keep it but without
""
$ ("# controlButton") Click (function () {var SHPname = $ ("# fname"). Val (); var text filemask = /^[az\.ss-] {2,} $ /; /// Check full name if (SHPname .length & gt; 0) {var testname = textfieldmask.test (SHPname); alert (testname); if (testname == true) {var tstnm = "ok"; warning (tstnm);} other {warning ("complete" Enter the name! "); $ ('#fname'). Focus (); // return false; do you get this return in any way? If you do not need it}} else {alert (" Please enter a name "); $ ('# fname'). Focus (); // right return; here itself}});
Comments
Post a Comment