/*indoc form validation - add on load??*/ $('document').ready(function(){ //get all form elements which need to be validated $('.formrow input').bind('blur',validateFormElementEvent); $('.formrow select').bind('blur',validateFormElementEvent); $('.formrow textarea').bind('blur',validateFormElementEvent); $('.formrow .submit').bind('click',validateAllForm); duoslideshow_default(); function validateFormElementEvent(event){ if($(event.target).attr('type')!="submit"){ validateFormElement(event.target,false); } } function validateFormElement(target,instant){ //first remove all current errors var fieldName=$(target).attr('name'); var error; if(fieldName){ //get validation type var validationType=fieldName.replace(/[^_]+__/,''); if(validationType=="mandatory" && $(target).val()=="" ){ error="You must fill out this field"; } if(validationType=="email" && !$(target).val().match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)){ error="This must contain an email address"; } if(validationType=="phone" && !$(target).val().match(/[0-9 .()+-]{6,20}/)){ error="This must contain a telephone number"; } if(validationType=="url" && !$(target).val().match(/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/)){ error="This must contain a website address"; } if(validationType=="age" && ($(target).val()-0)>0 && ($(target).val()-0)<160 ){ error="This must contain an age"; } if(validationType=="_number" && ($(target).val().match(/[^0-9\., ]+/) || $(target).val().length<1)){ error="This must contain a number "; } } if(error){ //absolutely postion an error near field?, then set a timer to remove them all after 5 seconds? if($(target).parent().find('.formError').length==0){ $(target).after('