$( document ).ready(function() { $( ".validate_property_domain" ).on( "keyup", function() { validate_property_domain(); }); $( "#customer_sign_up_form" ).submit(function( event ) { return validate_sign_up_form(); }); $( "#contact_us_form" ).submit(function( event ) { return validate_contact_us_form(); }); }); function validate_property_domain() { var property_domain = $("#property_domain").val(); var formData = {property_domain:property_domain}; var result = $.ajax({ url : "ajax_validate_domain.php", type: "POST", data : formData, async: false }).responseText; result = result.trim(); if (result != "true") $( ".validate_property_domain").next().html(result); else $( ".validate_property_domain").next().html(''); return result; } function validate_sign_up_form() { var valid = true; if (!validate_email($("#email_address").val())) { $( "#email_address").next().html("Email address is invalid"); valid = false; } else $( "#email_address").next().html(''); if ($( "#customer_name").val() == "") { $( "#customer_name").next().html("Field must not be blank"); valid = false; } else $( "#customer_name").next().html(''); if ($("#property_name").val() == "") { $( "#property_name").next().html("You must choose a name"); valid = false; } else $( "#property_name").next().html(''); if (!check_upper_lower_numeral($("#administrator_password").val())) { $( "#administrator_password").next().html("Password must have upper case, lower case and a numeral"); valid = false; } else if ($("#administrator_password").val().length < 8) { $( "#administrator_password").next().html("Password must be at least 8 characters"); valid = false; } else $( "#administrator_password").next().html(''); if ($("#administrator_password").val() != $("#repeat_administrator_password").val()){ $( "#repeat_administrator_password").next().html("Passwords must match"); valid = false; } else $( "#repeat_administrator_password").next().html(''); if(grecaptcha.getResponse() == "") { $( "#recaptcha_holder").next().html("You must click the recaptcha"); valid = false; } else $( "#recaptcha_holder").next().html(''); return valid; } function validate_contact_us_form() { valid = true; if(grecaptcha.getResponse() == "") { $( "#recaptcha_holder").next().html("You must click the recaptcha"); valid = false; } else $( "#recaptcha_holder").next().html(''); return valid; } function check_upper_lower_numeral(password) { var regex = /(?=.\d)/ if (!regex.test(password)) { //alert('fail numeral'); return false; } var regex = /(?=.[a-z])/ if (!regex.test(password)) { //alert('fail small letter'); return false; } var regex = /(?=.*[A-Z])/ if (!regex.test(password)) { //alert('fail capital letter'); return false; } return true; } function validate_email(email) { var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; return re.test(email); }