/ Published in: jQuery
Expand |
Embed | Plain Text
function checkFields() { var ok = true; var errStr = "Please fill the following fields correctly: \n"; if($('#contactForm #name').val() == 'Name') { ok = false; errStr += 'Name \n'; } if(isValidEmail($('#contactForm #mdrlyj-mdrlyj').val()) == false) { ok = false; errStr += 'Email Address \n'; } if($('#contactForm #cm-f-olrllh').val() == 'Company Name') { ok = false; errStr += 'Company Name \n'; } if(!isValidPostcode($('#contactForm #Postcode').val())) { ok = false; errStr += 'Postcode \n'; } if(!ok) { alert(errStr); } else { submitform('#contactForm'); } } function isValidEmail(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = email; if(reg.test(address) == false) { return false; } else { return true; } } function isValidPostcode(p) { var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i; return postcodeRegEx.test(p); }
You need to login to post a comment.
