Advertisement
dhtmlextreme

How To Format Phone Number With Crossplatform Javascript

Sep 29th, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.66 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Phone Validation</title>
  5. <script>
  6. function isPhone(el,evt) {
  7.     evt = (evt) ? evt : window.event;
  8.     var charCode = (evt.which) ? evt.which : evt.keyCode;
  9.     if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  10.        return false;
  11.     }
  12.     if(el.value.length==3||el.value.length==7||el.value.length==13) {el.value=el.value+"-";}
  13.     return true;
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <p id="para">please Enter your phone number and press the button to test its validity:</p>
  19.  
  20. <form action="#">
  21. <input type="text" id="phone" onkeypress="return isPhone(this,event)" oncontextmenu="return false"/>
  22. </form>
  23. </body>
  24. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement