javascript - Validating mobile no. of users -


i have following function validate mobile no.

 function validate() { var = document.form.mobile_no.value;  if(a=="") { alert("please enter contact number"); //document.form.mobile_no.focus(); return false; } if(isnan(a)) { alert("enter valid mobile number(like : 9566137117)"); //document.form.mobile_no.focus(); return false; } if((a.length < 1) || (a.length > 10)) { alert(" mobile number must 1 10 integers"); //document.form.mobile_no.select(); return false; } 

}

i have called function form as:

<form action="" method="post"  onsubmit="validate()" id="teacher_form"> 

and input user taken as:

but process not validating result should. entry accepted without input validation.

you can use regular expression as

var regexmobile = /^[0-9]+$/; var = document.form.mobile_no.value;  if (a.length < 10 || !a.match(regexmobile)) {     alert("enter valid 10 digit mobile number");     return false; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -