RegExp's test()

RegExp.test() accepts a string argument and returns true if the pattern matches and false if it does not.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var text = "000-00-0000"; 
        var pattern = /\d{3}-\d{2}-\d{4}/; 
        if (pattern.test(text)){ 
            document.writeln("The pattern was matched."); 
        } 
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

REGEXP:
  1. The Regexp Type
  2. RegExp constructor
  3. RegExp Instance Properties
  4. RegExp's exec() does the matching.
  5. RegExp's test()
  6. RegExp's toLocaleString() and toString()
  7. RegExp Constructor Properties