米国の 50 州のうち約 38 州を含む配列に依存するアラートがあります。正常に動作します (すばらしい人々の助けに感謝します)。文字 (つまり、WA、OR、GA など)。小文字 (例: wa、or、ga)、または大文字と小文字の組み合わせ (例: Wa、Or、Ga)、または記号 (例: WA - ワシントン、OR - オレゴン、GA - ジョージア) を入力する場合はどうでしょうか。すべてのバリエーションをキャッチする、これを行うより正確な方法があるかどうか疑問に思っています。
私が言及しているアラートは最後のもので、下部にある #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>