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" src="/scripts/validate.js" type="text/javascript"></script>
</head>
<body>
<form name="myForm" id="myForm" onSubmit="return validate(myForm)">
Name: <input type=text name="Name"
VALIDATOR="notEmptyPat"
><br>
Email Address: <input type=text name="Email_Address"
VALIDATOR="emailPat"
><br>
<input type=submit value="Submit">
</form>
</body>
</html>
function replace(haystack, oldNeedle, newNeedle) {
i = haystack.indexOf(oldNeedle);
r = "";
if (i == -1) return haystack;
r += haystack.substring(0,i) + newNeedle;
if (i + oldNeedle.length < haystack.length)
r += replace(haystack.substring(i + oldNeedle.length, haystack.length), oldNeedle, newNeedle);
return r;
}
function validate(objForm) {
var PatternsDict = new Object();
PatternsDict.zipPat = /\d{5}(-\d{4})?/; // matches zip codes
PatternsDict.
emailPat
= /.*@.*\..*/; // matches email addresses
PatternsDict.
notEmptyPat
= /.{1,}/; // matches at least one character
PatternsDict.numberPat = /\d/; // matches numbers only
PatternsDict.pwPat = /^\D{1}\S{3,9}$/; // matches between 4 and 10 characters with non-digit leading
PatternsDict.currencyPat = /\$\d{1,3}(,\d{3})*\.\d{2}/; // matches currency with commas
PatternsDict.timePat = /^([1-9]|1[0-2]):[0-5]\d$/; // matches times
var elArr = objForm.elements;
for(var i=0; i<elArr.length; i++)
with(elArr[i]) {
var v = elArr[i].VALIDATOR;
if(!v) continue;
var thePat = PatternsDict[v];
var gotIt = thePat.exec(value);
if(!gotIt) {
var returnStr;
readName = replace(name, "_", " ");
returnStr = "The " + readName + " field is invalid, this field is required in order to submit this form. Please try again!";
alert(returnStr);
return false;
}
}
return true;
}