javascript - How to check whether the entered mobile is landline or mobile using PhoneFormat.js? -
this example form. have take 1 text box, enter mobile number , choose country drop-box menu, validating mobile number country have used http://www.phoneformat.com/. here have given 1 method isvalidnumber(phno, country)
validate phone number country (both landline number , mobile number).
my requirement need allow mobile number, have used getnumbertype(phno)
, not giving results, can me how check whether entered number landline or mobile number?
<form name="fm" method="post"> <input type="text" name="phno" id="phno"> <br> <select id="ultra"> <option value="0">select</option> <option value="in">india</option> <option value="au">australia</option> <option value="cn">china</option> <option value="us"> america </option> </select><br><br> <input type="submit" value="check" onclick="run()"> </form> <script> function run() { var phoneutil = i18n.phonenumbers.phonenumberutil.getinstance(); var phno = document.getelementbyid("phno").value; alert('phone number '+phno); var res=isvalidnumber(phno, country); var country=document.getelementbyid("ultra").value; alert('country code '+country); try{ var res1=getnumbertype(phno); alert('type of phone number '+res1); }catch(e){ alert(e); } alert("validation result "+res); } </script>
here have created own method , included in phoneformat.js (http://www.phoneformat.com/) mobile give 1, fixed_line give 0.
function ismobilenumber(phone, country) { /*
tests whether number given number mobile or not. */ //alert('hello ismobilenumber()'); try { var phone = cleanphone(phone); var phoneutil = i18n.phonenumbers.phonenumberutil.getinstance(); var number = phoneutil.parseandkeeprawinput(phone, country); // alert('hello ismobilenumber'+phoneutil.getnumbertype(number)); if(phoneutil.getnumbertype(number)==1){ return true; } return false; } catch (e) { alert(e); //return false; } }
Comments
Post a Comment