我有一个警报,该警报依赖于一个包含 50 个美国中的大约 38 个的数组,它工作正常(感谢您的帮助)但现在我担心用户可能会输入我目前使用的格式的变体,即两个大写字母(即 WA、OR、GA 等)。如果他们要输入小写字母(即 wa, or, ga)或者可能是大写和小写字母的组合(即 Wa, Or, Ga)或带有符号(即 WA - Washington, OR - Oregon, GA - Georgia),该怎么办?想知道是否有更准确的方法可以捕捉所有变化。
我指的是最后一个警报,底部指向#address_province。
请注意,我在使用 Javascript 和 jQuery 方面都很陌生,因此您可以提供尽可能多的详细信息,我们将不胜感激。
非常感谢您提前。
<script>
// Hides shipping info fieldset if ship to billing is checked
$(function () {
$("#ship_to_billing").change(function () {
if ($(this).is(":checked")) $("#shipping_info").hide();
else $("#shipping_info").show();
});
});
// Validates address fields are filled out unless ship to billing is checked...
function validateShipping() {
if (!$("#ship_to_billing").is(":checked")) {
var inputs = $("#shipping_info input");
var ready = true;
inputs.each(function () {
if ($(this).val() == '') {
ready = false;
return false;
}
});
if (!ready) {
alert("Please tell us where to send this. Either choose ship to Billing Address or fill out both the Recipient Name as well as Shipping Address fields. Thanks!");
return false;
}
}
// Makes sure age verification is checked
if (!$('#age_verification').is(':checked')) {
alert("Please verify you are 21 years of age or older.");
return false;
}
// Confirms province is allowed for wine shipping
var states = ["AK", "AZ", "CA", "CO", "CT", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "LA", "ME", "MD", "MI", "MN", "MO", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OR", "SC", "TN", "TX", "VT", "VA", "WA", "WV", "WI", "WY"];
if ($.inArray($("#address_province").val(), states) <0) {
alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item.");
return false;
}
return true;
}
</script>