HTML and CSS Reference
In-Depth Information
EXAMPLE 17.13 ( CONTINUED )
document.write(result+"<br />");
if (result){
document.write("<b>The reg_ex /[A-Za-z0-9_]/ matched the
string\""+ textString +"\".<br />");
}
else{
alert("No Match!");
}
</script>
</body>
</html>
EXPLANATION
1
A regular expression object, an alphanumeric character in the bracketed character
class [A-Za-z0-9_] is assigned to the variable called reg_expression . This regular
expression matches a string that contains at least one character in the character
class ranging between A and Z , a and z , 0 and 9 , and the underscore character, _.
2
User input is entered in the prompt dialog box and assigned to the variable text-
String . In this example the user entered Take 5 .
3
The regular expression test method will return true because this string Take 5 con-
tains at least one alphanumeric character (see Figure 17.14).
Figure 17.14 User entered Take 5 (top). The string contained at least one
alphanumeric character (bottom).
EXAMPLE 17.14
<html>
<head><title>The Character Class and Negation</title></head>
<body>
Search WWH ::




Custom Search