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>