| |
26. 6. 7. Regular Expression Tester Form |
|
<html>
<head>
<title>Regular Expression Tester</title>
<script type="text/javascript" language="javascript">
<!-- //
function TestString(){
testString = document.SimpleForm.TestInput.value;
var pattern = document.SimpleForm.FirstInput.value;
myRegExp = new RegExp(pattern);
if (myRegExp.test(testString)){
alert("The test string: " +testString + "\nmatched the current pattern: " + myRegExp);
} else{
alert("The test string: " +testString + "\ndid not match the current pattern: " + myRegExp);
}
}
function ClearAndSet(){
document.SimpleForm.reset();
SetFocus();
MaxNum = 0;
}
// -->
</script>
</head>
<body>
<h3>This page allows you to create and test regular expression patterns</h3>
<form name="SimpleForm">
<table>
<tr>
<td width="30%" align="right">Enter a pattern:</td>
<td><input name="FirstInput" type="text"></td>
</tr>
<tr>
<td width="30%" align="right">Enter a string to match the pattern:</td>
<td><input name="TestInput" type="text"></td>
</tr>
<tr>
<td width="25%" align="right"><button type="Button" onclick="ClearAndSet()">
Clear and Start again</button></td>
<td><button type="Button" onclick="TestString()">
Click to test the string you entered</button></td>
</tr>
</table>
</form>
</body>
</html>
|
|
|