I need to validate input text filed with below values , "PO BOX", POBOX, "GPO BOX" and "GPOX"
if someone enter those words into text box, alert them “We do not ship products to PO Box addresses”.
and remove entire text.
I have build below,
$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).blur(function(){
$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘PO
BOX’),
$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘POBOX’),
$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘GPO
BOX’),$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘GPOX’),$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘po
box’),$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘pobox’),$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘gpo
box’),$(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val()
== $(‘#objCheckoutRegistration_PhysicalAddress_txtAddressLine1’).val().match(‘gpox’)
{alert('We do not ship products to PO Box addresses'); $('#objCheckoutRegistration_PhysicalAddress_txtAddressLine1').val(''); $('#objCheckoutRegistration_PhysicalAddress_txtAddressLine1').focus(); } }); });
but problem is it’s only validating exact word,
I mean if add PO BOX 1145 and some other text, it wan’t validate.
Try using a regex. I’m not regex guru, but you just need to look for text which has ‘PO’ followed by ‘BOX’ somewhere in your string.
So, this should do the trick