function check(conditions) { for(var index=0; index cond.value) { alert(msg); return false; } } else if(is == 'lesser') { if($(id).value < cond.value) { alert(msg); return false; } } else if(is == 'file') { //The valid file types should be given in the 'value' field as a comma seperated list if($(id).value) { var parts; if($(id).value.indexOf("/") + 1) parts = $(id).value.split("/"); else parts = $(id).value.split("\\"); var ext = parts[parts.length-1].split("."); ext = ext[ext.length-1].toLowerCase(); var allowed = cond.value.toLowerCase().split(","); var found = false; for(var i in allowed) { if(ext == allowed[i]) { found = true; break; } } if(!found) { if(msg) error = msg; else if(name) error = "The " + name +" should be any of these file types : " + cond.value; else error = "Invalid file type"; alert(error); return false; } } } else if(is == 'nan' || is == 'not_number') { //Warning: Decimals will get thru if(isNaN($(id).value)) { if(msg) error = msg; else if(name) error = "The " + name +" should be a number"; alert(error); $(id).focus(); return false; } } else if(is == 'not_email') { //If the field does not match the email regexp, an error is shown if($(id).value.search(/^[\w\-\.]+\@[\w\-\.]+\.[a-z\.]{2,5}$/) == -1) { if(msg) error = msg; else if(name) error = "The " + name +" should be a valid email address"; else error = "Invalid Email address provided" alert(error); $(id).focus(); return false; } } else if(is == 'has_weird') { //Check for weird chars if($(id).value.search(/^[\w\-]*$/) == -1) { if(msg) error = msg; else if(name) error = "The " + name +" should not have weird characters"; else error = "Weird characters where found in the input" alert(error); $(id).focus(); return false; } } else if(is == 'not_name') { //Check for chars that cannot appear in a name if($(id).value.search(/^[\w\'\(\)\,\.\/ ]*$/) == -1) { if(msg) error = msg; else if(name) error = "The " + name +" has invalid characters"; else error = "Invalid characters where found in the input" alert(error); $(id).focus(); return false; } } } return true; }