Get Access to the Client Centre
$(document).ready(function(){
$('#hPot').hide();
var validPolicy = false;
var validEmail = false;
var validMobile = false;
var validDob = false;
// Handle the mobile phone numbers
$(".mobile-number").intlTelInput({
initialCountry: 'ie',
preferredCountries: ['ie', 'gb'],
placeholderNumberType: 'MOBILE',
formatOnDisplay: true,
hiddenInput: "inputPhone",
utilsScript: "/bgsi/public/js/utils.js"
});
// Initialise Policy Number entry field
$('#clientpolicynumber').autoNumeric('init', {vMin: '0', vMax: '99999999', mDec:'0', aSep:'', lZero:'keep'});
validatePolicyNumberInput($("#clientpolicynumber"));
validateEmailInput($("#clientemail"));
// Wait for 1 second to allow intlTelInput to load properly
setTimeout(function () {
validateMobile($(".mobile-number"));
}, 1000);
validateDateInput($("#clientdob"));
// Validation on the policy number - when it changes
$("#clientpolicynumber").keyup(function() {
var clientpolicynumber = $(this);
validatePolicyNumberInput(clientpolicynumber);
validateInputs();
});
// Validation on the email address - when it changes
$("#clientemail").on("input", function(){
var emailInput = $(this);
validateEmailInput(emailInput);
validateInputs();
});
// Validation on the mobile phone numbers - when they change
$(".mobile-number").on("input", function(){
var mobileInput = $(this);
validateMobile(mobileInput);
validateInputs();
});
// Validation on the date of birth - when it changes
$("#clientdob").on("input", function(){
var dobInput = $(this);
setTimeout(function () {
validateDateInput(dobInput);
validateInputs();
}, 100);
});
});
function validatePolicyNumberInput(clientpolicynumber) {
$(clientpolicynumber).closest('.form-group').removeClass('has-error')
$('#invalidPolicyNo').addClass('hide');
$('#invalidPolicyLength').addClass('hide');
validPolicy = true;
var subStr1 = clientpolicynumber.val().toString().substring(0,1);
var subStr3 = clientpolicynumber.val().toString().substring(0,3);
if (subStr3 === "605" || subStr1 === "3" || subStr3 === "200" || subStr3 === "201")
{
$(clientpolicynumber).closest('.form-group').addClass('has-error')
$('#invalidPolicyNo').removeClass('hide');
validPolicy = false;
}
if (clientpolicynumber.val().length > 0 && clientpolicynumber.val().length != 8)
{
$(clientpolicynumber).closest('.form-group').addClass('has-error')
$('#invalidPolicyLength').removeClass('hide');
validPolicy = false;
}
}
function validateEmailInput(emailInput) {
$(emailInput).closest('.form-group').removeClass('has-error');
$(emailInput).closest('.form-group').removeClass('has-success');
$('#validEmail').addClass('hide');
validEmail = true;
var email = $(emailInput).val();
if ($.trim(email))
{
if (validateEmailAddress(email))
{
$(emailInput).closest('.form-group').addClass('has-success');
}
else
{
$(emailInput).closest('.form-group').addClass('has-error');
$('#validEmail').removeClass('hide');
$('#validEmail').html('Please enter a valid email address');
validEmail = false;
}
}
return;
}
function validateMobile(mobileInput) {
$(mobileInput).closest('.form-group').removeClass('has-error');
$(mobileInput).closest('.form-group').removeClass('has-success');
$('#validMobile').addClass('hide');
validMobile = true;
if ($.trim(mobileInput.val()))
{
// Get the type of the number entered
// 0 = FIXED_LINE
// 1 = MOBILE
// 2 = FIXED_LINE_OR_MOBILE - Can't tell the difference for US numbers
var numberType = mobileInput.intlTelInput("getNumberType");
if (numberType == "1" || numberType == "2")
{
$(mobileInput).closest('.form-group').addClass('has-success');
}
else
{
$(mobileInput).closest('.form-group').addClass('has-error');
$('#validMobile').removeClass('hide');
$('#validMobile').html('Please enter a valid mobile number');
validMobile = false;
}
}
return;
}
function validateDateInput(dateInput) {
$(dateInput).closest('.form-group').removeClass('has-error');
$(dateInput).closest('.form-group').removeClass('has-success');
$('#validDob').addClass('hide');
validDob = true;
var dob = $(dateInput).val();
if ($.trim(dob))
{
if (moment(dob, 'DD/MM/YYYY').isValid())
{
$(dateInput).closest('.form-group').addClass('has-success');
}
else
{
$(dateInput).closest('.form-group').addClass('has-error');
$('#validDob').removeClass('hide');
$('#validDob').html('Please enter a valid date of birth');
validDob = false;
}
}
return;
}
function validateInputs() {
$("#doContact_submit").prop("disabled", false);
$("#doContact_submit").html('Submit');
if (!validPolicy || !validEmail || !validMobile || !validDob)
{
$("#doContact_submit").prop("disabled", true);
$("#doContact_submit").html('Submit Not Allowed - Invalid Inputs');
}
return;
}
function validateEmailAddress(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validateForm() {
var hPotVal = $('#hPotField').val();
if (hPotVal != "") {
alert("You seem to be a bot");
return false;
}
return true;
}
Working, please wait ...