I have the code below on my form fields to validate it's not empty. If empty, a CSS error class is added.
if(!$('.order-modal input[name="address"]').val()){
$('.order-modal input[name="address"]').addClass('ww-error');
form_errors += 1;
}else{
$('.order-modal input[name="address"]').removeClass('ww-error');
}
I also want to check if the same form field contains "P.O. box" or "PO box" or p.o. box or po box and if it does change placeholder text and the error class.
The code below works in a way but not perfectly as I want it?
if(!$('.order-modal input[name="address"]').val()){
$('.order-modal input[name="address"]').addClass('ww-error');
form_errors += 1;
}else if($('.order-modal input[name="address"]').val() == 'P.O. box'){
$('.order-modal input[name="address"]').val('');
$('.order-modal input[name="address"]').attr('placeholder', 'P.O. box not accepted');
$('.order-modal input[name="address"]').addClass('ww-error');
form_errors += 1;
}else{
$('.order-modal input[name="address"]').removeClass('ww-error');
}
Thanks! /Robert