Skip to content

Instantly share code, notes, and snippets.

@SheriSmith
Created November 26, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SheriSmith/cad3849a1092d4d2568c to your computer and use it in GitHub Desktop.
Save SheriSmith/cad3849a1092d4d2568c to your computer and use it in GitHub Desktop.
Validation.add('validate-pobox','We cannot ship to your P.O. Please check the button to ship to a different address.',function(field_value) {
// setup a regex var for pretty much every possibility of PO box...
var regex = /[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]/;
// if the field_value contains PO Box
if(field_value.match(regex))
{
if (document.getElementById('billing:use_for_shipping_yes').checked == true)
{
return false;
}
return true;
}
else
{
if(!field_value.match(regex))
{
return true;
}
}
});
Validation.add('validate-pobox2','We cannot ship to your P.O. Please check the button to ship to a different address.',function(field_value) {
// setup a regex var for pretty much every possibility of PO box...
var regex2 = /[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]/;
// if the field_value contains PO Box
if(field_value.match(regex2))
{
if (document.getElementById('billing:use_for_shipping_yes').checked == true)
{
return false;
}
return true;
}
else
{
if(!field_value.match(regex2))
{
return true;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment