Function to determine if a string contains characters only from another - Javascript RegExp

Javascript examples for RegExp:RegExp test

Description

Function to determine if a string contains characters only from another

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(){/*ww w.ja  v  a  2s. co  m*/
function isChar(str) {
  return /^[a-zA-Z()]+$/.test(str);
}
var allowed = 'abcdefghijklmnopqrstuvwxyz';
if(isChar(allowed )){
    console.log('a-z cool :)');
}else{
    console.log('Enter only Char between a-z');
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials