mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-04 12:22:24 +08:00
https://stackoverflow.com/questions/68126354/characters-only-validation-for-woocommerce-first-name-last-name
10 lines
489 B
Text
10 lines
489 B
Text
add_action( 'woocommerce_after_checkout_validation', 'bks_validate_fname_lname', 10, 2);
|
|
|
|
function bks_validate_fname_lname( $fields, $errors ){
|
|
if (!preg_match( '/^[a-zA-Z ]+$/', $fields[ 'billing_first_name' ])){
|
|
$errors->add( 'validation', 'First name should only have no special characters.' );
|
|
}
|
|
if (!preg_match( '/^[a-zA-Z ]+$/', $fields[ 'billing_last_name' ])){
|
|
$errors->add( 'validation', 'Last name should only have no special characters.' );
|
|
}
|
|
}
|