dhtmlextreme

How To Format Phone Number With Crossplatform Javascript 2

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