Preventing special characters from being added in checkout inputs.
The checkout will need to be unlocked so that the code can be added to checkout.liquid.
Find the document ready at the bottom of checkout.liquid.One thing to keep in mind is you may need to change the ids for the inputs depending on what checkout version you are working with. I've placed the code below for the id's that are labeled billing rather than shipping.
<script type="text/javascript"> $(document).ready(function() {Place this code right after for #checkout_shipping ids.
$('#checkout_shipping_address_first_name, #checkout_shipping_address_last_name, #checkout_shipping_address_address1, #checkout_shipping_address_address2, #checkout_shipping_address_city, #checkout_shipping_address_province, #checkout_shipping_address_zip').keypress(function(e) { console.log("cool"); var regex = new RegExp("^[a-zA-Z0-9 ]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; });Or place this code right after for #checkout_billing ids.
$('#checkout_billing_address_first_name, #checkout_billing_address_last_name, #checkout_billing_address_address1, #checkout_billing_address_address2, #checkout_billing_address_city, #checkout_billing_address_province, #checkout_billing_address_zip').keypress(function(e) { console.log("cool"); var regex = new RegExp("^[a-zA-Z0-9 ]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; });