<script type="text/javascript" language="JavaScript" >
<!--
//
//Edit these variable to suit
//
//Build up the required fields array
//
var validfields = new Array();
validfields[0] = "name";
validfields[1] = "lastname";
//validfields[2] = "email";
//validfields[3] = "telephone";
//
//what type of field is it
//choices are
//txt = textbox or textarea
//radio = radio group
//chkbx = checkbox
//dropbox = select > option
//
var fieldtype = new Array();
fieldtype[0] = "txt";
fieldtype[1] = "txt";
//fieldtype[2] = "txt";
//fieldtype[3] = "txt";
//
//whats allowed in the field
//na = not applicable use for non txt validation
//asc = a-z A-Z 0-9 _ and space
//textonly = a-z A-Z - no spaces
//email = valid email address
//num = 0-9 and spaces
//numonly = 0-9 no spaces
//dateUK = date in the format dd/mm/yyyy
//dateUS = date in the format mm/dd/yyyy
//
var fieldallow = new Array();
fieldallow[0] = "asc";
fieldallow[1] = "asc";
//fieldallow[2] = "asc";
//fieldallow[3] = "num";
//fieldallow[8] = "dateUK";
//
//set this to the same value as the name of your form
//
var formname = "faultform";
//
//Bg colours
//bcol = normal
//bcolerr = error
//
var bcol = "white";
var bcolerr = "FFFFFF";
//
//Text colours
//tcol = same as bcol
//tcolerr = error colour
//
var tcol= "white";
var tcolerr = "red";
//
//Settings for NS4x
//
var nserrwidth=140;
var nserrorpos ="center";//left right center
//
//End of user settings do not edit below this line
//
/*
*/
//browser detect
//
var Mac = (navigator.userAgent.indexOf("mac")!=-1) || (navigator.userAgent.indexOf("Mac")!=-1);
var opera = (navigator.userAgent.indexOf('Opera')!=-1);
var msie = (navigator.userAgent.indexOf('MSIE')!=-1);
var moz = (navigator.userAgent.indexOf('Gecko')!=-1);
var Nav4 = (document.layers);
if (opera && msie || opera){var opera=1; msie=0;}
if (msie && !opera){msie=1;}
if(msie || moz){var dom =1;}
//
//End browser detect
//
function validform(){
var err=1;
var etext="";
//
//Internet Explorer
//Mozilla
//Netscape 6
//Opera
//
if (dom || opera){
var i=0;
//reset the styles to white
while (i != validfields.length ){
eval("document.getElementById('err"+i+"').style.backgroundColor='"+bcol+"';");
eval("document.getElementById('err"+i+"').style.color='"+tcol+"';");
i++;
}
//check the required fields from array
var i=0;
while (i != validfields.length ){
whatfield = "";
//
//text - textarea
if(fieldtype[i] == "txt"){
whatfield = eval("document."+formname+"."+validfields[i]+".value");
}
//
//radio
if(fieldtype[i] == "radio"){
radcount = eval("document."+formname+"."+validfields[i]+".length");
for (var a = 0; a < radcount; a++){
if (eval("document."+formname+"."+validfields[i]+"["+a+"].checked")){
whatfield = "OK";
}
}
}
//
//checkbox
if(fieldtype[i] == "chkbx"){
if (eval("document."+formname+"."+validfields[i]+".checked")){
whatfield = "OK";
}
}
//
//Select
if(fieldtype[i] == "dropbox"){
radstr = "document."+formname+"."+validfields[i];
rs2 = eval(radstr+".options["+radstr+".selectedIndex].value");
whatfield = rs2;
}
//
//
// Check Data
//
//
//
//email address
if (fieldallow[i] == "email" && whatfield != ""){
var re=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;
if (!re.test(whatfield)) {
whatfield="";
}
}
//END email address
//
//
//a-z A-Z _ and space
if (fieldallow[i] == "asc" && whatfield != ""){
var re = /^[\w ]+$/;
if (!re.test(whatfield)) {
whatfield="";
}
}
//END -z A-Z _ and space
//
//
//a-z A-Z ONLY
if (fieldallow[i] == "textonly" && whatfield != ""){
var re = /^[a-zA-Z]+$/;
if (!re.test(whatfield)) {
whatfield="";
}
}
//END a-z A-Z ONLY
//
//
//0-9 and space
if (fieldallow[i] == "num" && whatfield != ""){
var re = /^[0-9 ]+$/;
if (!re.test(whatfield)) {;
whatfield="";
}
}
//END 0-9 and space
//
//
//0-9
if (fieldallow[i] == "numonly" && whatfield != ""){
var re = /^[0-9]+$/;
if (!re.test(whatfield)) {;
whatfield="";
}
}
//END 0-9
//
//
//Date UK and US date formats
if (fieldallow[i] == "dateUK" && whatfield != "" || fieldallow[i] == "dateUS" && whatfield != ""){
var re = /^\d{2}\/\d{2}\/\d{4}$/;
var isitok=0;
if (re.test(whatfield)) {
var bits = whatfield.split("/");
isitok = (bits.length == 3); // should be three components
if (isitok)
{
if(fieldallow[i] == "dateUK"){
day = parseInt(bits[0]);
month = parseInt(bits[1]);
}
if(fieldallow[i] == "dateUS"){
day = parseInt(bits[1]);
month = parseInt(bits[0]);
}
var year = parseInt(bits[2]);
isitok = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (bits[2].length == 4);
}
}
if(!isitok || !re.test(whatfield)){
whatfield="";
}
//EndDate UK and US date formats
//
}
//
//
// End Check Data
//
//
//
//if the required fields are empty reveal the warning message
if(whatfield == "" ){
eval("document.getElementById('err"+i+"').style.backgroundColor='"+bcolerr+"';");
eval("document.getElementById('err"+i+"').style.color='"+tcolerr+"';");
err=0;
}
//
//continue count
i++;
}
}
if(Nav4){
err=1;
var i=0;
var dateformat="";
var ErrString ="";
var whatfield="";
//check the required fields from array
while (i != validfields.length ){
whatfield="";
//
//text - textarea
if(fieldtype[i] == "txt"){
whatfield = eval("document."+formname+"."+validfields[i]+".value");
}
//
//radio
if(fieldtype[i] == "radio"){
radcount = eval("document."+formname+"."+validfields[i]+".length");
for (var a = 0; a < radcount; a++){
if (eval("document."+formname+"."+validfields[i]+"["+a+"].checked")){
whatfield = "ok";
}
}
}
//
//END Radio
//
//checkbox
if(fieldtype[i] == "chkbx"){
if (eval("document."+formname+"."+validfields[i]+".checked")){
whatfield = "ok";
}
}
//
//Select
if(fieldtype[i] == "dropbox"){
radstr = "document."+formname+"."+validfields[i];
rs2 = eval(radstr+".options["+radstr+".selectedIndex].value");
whatfield = rs2;
}
//
//
//Check Data
//
//
//
//email address
if (fieldallow[i] == "email" && whatfield != ""){
var re=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;
if (!re.test(whatfield)) {
ErrString += ""+validfields[i]+" = Valid Email address only<br><br>";
whatfield="ok";
}
}
//END email address
//
//
//a-z A-Z _ numbers and space
if (fieldallow[i] == "asc" && whatfield != ""){
var re = /^[\w ]+$/;
if (!re.test(whatfield)) {
ErrString += ""+validfields[i]+" = letters _ Nos and spaces only<br><br>";
whatfield="ok";
}
}
//a-z A-Z _ numbers and space
//
//
//a-z A-Z _ numbers and space
if (fieldallow[i] == "textonly" && whatfield != ""){
var re = /^[a-zA-Z]+$/;
if (!re.test(whatfield)) {
ErrString += ""+validfields[i]+" = a-z A-Z only - No spaces allowed<br><br>";
whatfield="ok";
}
}
//END a-z A-Z ONLY
//
//
//0-9 and space
if (fieldallow[i] == "num" && whatfield != ""){
var re = /^[0-9 ]+$/;
if (!re.test(whatfield)) {;
whatfield="ok";
ErrString += ""+validfields[i]+" = numbers and spaces only<br><br>";
}
}
//END 0-9 and space
//
//
//0-9 and space
if (fieldallow[i] == "numonly" && whatfield != ""){
var re = /^[0-9]+$/;
if (!re.test(whatfield)) {;
whatfield="ok";
ErrString += ""+validfields[i]+" = numbers only - NO spaces<br><br>";
}
}
//END 0-9 and space
//
//
//date UK and US
if (fieldallow[i] == "dateUK" && whatfield != "" || fieldallow[i] == "dateUS" && whatfield != ""){
var re = /^\d{2}\/\d{2}\/\d{4}$/;
var isitok=0;
if (fieldallow[i] == "dateUK"){dateformat="(dd/mm/yyyy)";}
if (fieldallow[i] == "dateUS"){dateformat="(mm/dd/yyyy)";}
if (re.test(whatfield)) {
var bits = whatfield.split("/");
isitok = (bits.length == 3); // should be three components
if (isitok)
{
if(fieldallow[i] == "dateUK"){
day = parseInt(bits[0]);
month = parseInt(bits[1]);
}
if(fieldallow[i] == "dateUS"){
day = parseInt(bits[1]);
month = parseInt(bits[0]);
}
var year = parseInt(bits[2]);
isitok = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (bits[2].length == 4);
}
}
if(!isitok || !re.test(whatfield)){
whatfield="ok";
ErrString += ""+validfields[i]+" = "+dateformat+"<br><br>";
}
//END date
//
}
// End Check Data
//if the required fields are empty reveal the warning message
if(whatfield == ""){
ErrString += validfields[i]+" required<br><br>";
err=0;
}
i++;
}
}
//do not submit the form if there are errors
//REQUIRED
if (err==0){ return false;}
}