Match Regex with input tel box - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Match Regex with input tel box

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from   w  w w  .j  a v  a2 s . c  om*/
var input = document.getElementsByName('contact[phone]')[0];
input.addEventListener('change', function() {
        console.log('Is valid?',  input.value.search(new RegExp(input.getAttribute('pattern'))) !== -1);
}, false);
    }

      </script> 
   </head> 
   <body> 
      <input type="tel" name="contact[phone]" id="phone" required pattern="^\d+$">  
   </body>
</html>

Related Tutorials