IsValid.js
var PatternsDict = new Object();
PatternsDict.isZip = /^(\d{5}(-\d{4})?)?$/;
// matches zip codes
PatternsDict.isCurrency = /^\d{1,3}(,\d{3})*\.\d{2}$/;
// matches $17.23 or 14,281,545.45 or ...
PatternsDict.isTime = /^([1-2]?[0-9]?[:]?[0-6]?[0-9]?[:]?[0-6]?[0-9]?[ \tAaMmpP]?)*$/;
// matches 5:04 or 12:34
PatternsDict.isDate = new Array("^(([1-2]?[0-9]?)|([3][0-1]?)\/([1-9]?|[1][0-2]?)\/[0-2]?[0-9]?[0-9]?[0-9]?)*$","^(([0-9]?|([1][0-2]?))?\/(([0-2]?[0-9]?)|([3][0-1]))\/[0-2]?[0-9]?[0-9]?[0-9]?)*$");
// matches 12/31/1998 or 31/12/1998 or empty is allowed
PatternsDict.isAlpha = /^([A-Za-z\' \t])*$/;
// matches chuck Noris or empty is allowed
PatternsDict.isWord = /^([A-Za-z0-9_ \t\-])*$/;
// matches doto2_So
PatternsDict.isEmail = /^(((\w)+[-.!])?(\w[!]?)+@((\w)+[-.])+(\w{1,3}))?$/;
// matches k1234!@ting.tong.com or t@k.king.com or t-ding@dong.com
PatternsDict.isDigit = /^\d*$/;
//equivalent to [0-9]* matches 12312123 or empty is allowed
PatternsDict.isPhone = new Array("^(([A-Za-z0-9 ]+[-.]?)*)$","^[\(][0-9]+[\)](([A-Za-z0-9 ]+[-.]?)*)$");
// matches 425.640.8151 or 425-640-8151 or (425)640-8151or empty is allowed
PatternsDict.isTinyInt = new Array("^\[0-9]?$","^[0-9]?[0-9]?$","^[0-2]?[0-5]?[0-5]?$");
// value <= 255
PatternsDict.isSmallInt=new Array("^\[0-9]?$","^[0-9]?[0-9]?$","^[0-9]?[0-9]?[0-9]?$","^[0-9]?[0-9]?[0-9]?[0-9]?$","^[0-3]?[0-2]?[0-7]?[0-6]?[0-7]?$");
// value <= 32767
function validateForm(theForm){ // return true if all is well
var item = parent.document.all.tags('META'); //always returns true for
for( var count = 0;count<item.length;count++){ // japanese language
if(item[count].httpEquiv=='content-type'){
var NodeValue = item[count].content;
var pos = NodeValue.lastIndexOf('=');
NodeValue = NodeValue.substr(pos+1);
if(NodeValue=='shift-jis') return true;
}
}
var elArr = theForm.elements; // get all elements of the form into array
for(var i = 0; i < elArr.length; i++)
with(elArr[i]){ // for each element of the form...
if(elArr[i].required=="true"){
if(Trim(value)==''){
//L_NAME(expando attrib) is localized version of name attribute
alert(L_Empty + elArr[i].L_NAME);
elArr[i].focus();
return false;
}
}
var v = elArr[i].validator; // get validator, if any
if(!v) continue; // no validator property, skip
else {
if(PatternsDict[v].length > 0){
for(var j=0; j < PatternsDict[v].length; j++){
var TempPatternsDict = new RegExp(PatternsDict[v][j]);
var gotIt = TempPatternsDict.exec(Trim(value));
if(gotIt) break;
}
if(!gotIt){
alert(L_Invalid + elArr[i].L_NAME);
elArr[i].focus();
return false;
}
}
else{
var thePat = PatternsDict[v]; // select the validating regular expr
var gotIt = thePat.exec(Trim(value)); // run it on value of elArr[i]
if(!gotIt){
alert(L_Invalid + elArr[i].L_NAME);
elArr[i].focus();
return false;
}
}
}
}
return true;
}
function Trim(oldString) {
// is oldString made up completely of whitespace?
var emptyPattern = /^(\s*)$/;
if(emptyPattern.test(oldString))
// if so, return null string
return '';
else
// else, return non-whitespace characters from middle of oldString
return oldString.replace(/^\s*(.*\S+)\s*$/,"$1");
}