通过正则表达式,匹配任意大写“L”实例:
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script>
var myRegExp=/L/;
function Validate(entry){
return myRegExp.test(entry);
}
function ShowPrompt(){
var entry=prompt("This script tests for matches for the regular expression pattern:"+myRegExp+".\nType in a string and clik on the OK button.","Type your text here.");
if(Validate(entry)){
alert("There is a match!\n The regular expression pattern is:"+myRegExp+".\n");
}else{
alert("There is no match in the string you entrered.\n"+myRegExp+".\n The string that you entere was:'"+entry+"'.");
}
}
</script>
</head>
<body>
<form name="myFrom">
<button type="button" onclick="ShowPrompt()">Click here to enter text.</button>
</form>
</body>
</html>