HTML Form Field - How to require an input format - Node.js Regular expression

Node.js examples for Regular expression:Match

Description

HTML Form Field - How to require an input format

Demo Code

 Code:
 <html>//from  www .  ja  v  a 2  s  . c  o  m
    <head> 
       <meta name="viewport" content="width=device-width, initial-scale=1"> 
       <script type="text/javascript">
     window.onload=function(){
    var  string  = "(838)-888-8838";
    var pattern =  /^\(\d{3}\)\-\d{3}\-\d{4}$/; //for (XXX)-XXX-XXXX
    console.log(pattern.test(string));
    var  string2  = "838-838-8838";
    var pattern2 = /^\d{3}\-\d{3}\-\d{4}$/; // XXX-XXX-XXXX
    console.log(pattern2.test(string2));
     }
                
       </script> 
    </head> 
    <body>  
    </body>
 </html>

Related Tutorials