jquery - testing if value is numeric is not working when submitting a form -


i'm having simple code check if value numeric before submitting form form submits it's not numeric value

<form action="asdasd" method="post" id="my_form" > <input type="text" name="userphone" id="userphone" /> <br /> <input type="submit" name="register" id="register" value="register" /> </form> 

js code

$(document).ready(function() {  $('#userphone').blur(function () { var phone = $("#userphone").val(); var phonelen = phone.length;  if (!$.isnumeric(phone) || phonelen<6) {     $("#userphone").css("background-color", "#ff9f9f");     return false; } else {     $("#userphone").css("background-color", "#fff");     return true; } }) });  function check_user_phone(){  var phone = $("#userphone").val(); var phonelen = phone.length;  if (!$.isnumeric(phone) || phonelen<6) {     return false; } else {     return true; } }   $("#my_form").submit(function(){  if (!check_user_phone()) {     return false; } else {     return true; } }) 

but form still submitting data if phone value not numeric

try changing jsfiddle option onload no wrap - in <head>

jsfiddle:-http://jsfiddle.net/adiioo7/wfpbv/5/

js

jquery(function(){     $("#reg").submit(function(e){         if(!check_phone() ){               e.preventdefault();         }     }); }); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -