Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<html>
<head>
<script language="Javascript">
//verify function to verify all inputs with a set pattern
function verify(frmElem){
var regex, pattern, errmsg;
var result;
//loop through all form elements
for(var i = 0;i < frmElem.length;i++){
//try to grab the pattern
pattern = frmElem.elements(i).testcode;
//make sure there was a pattern
if(!(pattern===undefined)){
//create a regexp object with the specified pattern
regex = new RegExp(frmElem.elements(i).testcode,"i");
//test the value with the supplied pattern
if(!(regex.test(frmElem.elements(i).value))){
//oops, incorrect entry, get the error message
errmsg = frmElem.elements(i).testerror;
//if there wasn't one, make one up
if(errmsg===undefined){
errmsg = "Please double check the selected entry, it is incorrectly formated."
}
//do a std error reaction
alert(errmsg);
frmElem.elements(i).focus();
return false;
}
}
}
return true;
}
</script>
</head>
<body>
<!-- Some sample code -->
<form method="POST" action="sample.asp" onSubmit="return verify(this);">
Enter a Number: <input type="text" name="txtNum" testcode="^\d$" testerror="You may only enter a single number in the first input.">*<br>
Enter a Letter: <input type="text" name="txtLetter" testcode="^[a-zA-Z]$" testerror="You may only enter a single letter in the second input.">*<br>
Enter whatever you want: <input type="text" name="txtAnything"><br>
Enter a Phone Number: <input type="text" name="txtPhone" testcode="^\d{3}-\d{3}-\d{4}$" testerror="Please check that your phone number is in the correct format (###-###-####).">*<br>
Enter an Email: <input type="text" name="txtEmail" testcode="^[\w-_\.]+\@[\w-_]+(\.[\w-_]+)+$" testerror="Please check that your email is formatted correctly.">*<br>
<input type="submit" value="Submit">
</form>
</body>
</html>