HTML and CSS Reference
In-Depth Information
Figure 17.16 The user entered 126553 . It contains a 6 followed by any two digits.
EXAMPLE 17.16
<html>
<head><title>The Digit Meta Symbol Negated</title></head>
<body>
<script type="text/javascript">
1
var reg_expression = /[a-z]\D\D/;
2
var textString=prompt("Type a string of text","");
3
var result=reg_expression.test(textString) ;// Returns true
// or false
document.write(result+"<br />");
if (result){
document.write("<b>The regular expression /[a-z]\\D\\D/
matched the string\"" + textString +"\".<br />");
}
else{
alert("No Match!");
}
</script>
</body>
</html>
EXPLANATION
1
The variable is assigned a regular expression containing a letter, followed by two
single nondigits. The metasymbol \D represents the character class [^0-9].
2
The variable textString is assigned user input; in this example, Hello! was entered.
3
The regular expression test() method will return true because this string Hello!!
matches a lowercase letter, followed by two nondigit characters. See Figure 17.17.
Figure 17.17 The user entered a lowercase letter followed by two nondigits.
Search WWH ::




Custom Search