Mega Code Archive

 
Categories / JavaScript DHTML / Development
 

Whether a string is a valid phone number

<html>   <head>     <title>whether a string is a valid phone number</title>     <script type="text/javascript"> var telephoneString = "(103) 5555 5555"; var emailString = "b@m.com"; var pattern = /^(\(\d+\) ?)?(\d+[\- ])*\d+$/; var a = pattern.test(telephoneString); var b = pattern.test(emailString); document.write(a + "<BR>" + b);     </script>   </head>   <body>   </body> </html>