Trying to force Letters only (possibly also with non-English characters) in Woocommerce checkout field, First Name. we often have older customers so we need to control user input and prevent errors in advance.
What am I doing wrong?
NOTE: I'm aware of the Custom Validation thread Custom validation of WooCommerce checkout fields ... but it feels like this should be far simpler and specific solve?
Used Businessbloomers' code for forcing numbers only in Post Code field (works fine). SOURCE: https://businessbloomer.com/woocommerce-change-input-type-checkout-fields/
function bbloomer_change_checkout_field_input_type() {
echo "<script>document.getElementById('billing_postcode').type = 'number';
</script>";
}
add_action( 'woocommerce_after_checkout_form', 'bbloomer_change_checkout_field_input_type');
For Fname I changed type input to 'letter'.. but no result (still able to input numbers). Swapped 'type' for 'pattern', as below, but no luck.
function JBC_Force_letters_in_fname_field() {
echo "<script>document.getElementById('billing_first_name').pattern='[A- Za-z]';</script>";
}
add_action( 'woocommerce_after_checkout_form', 'JBC_Force_letters_in_fname_field');
- Expecting: David
- Getting/Allowing: Dav1D3