WooCommerce : Custom validation on checkout page for First and Last names to Contain Only Letters.

Code

Customer having name “1234” has placed order on your Woocommerce site?

We are in 21st century, but it’s still not possible that a human being having a name like 1234 or any other number.
Woocommerce allow to fill user information on it’s checkout page. It also allow create user account at time of checkout. on checkout page their are many fields provided by woocommerce which may have input type number or text.

Woocommerce allow user to fill number instead of text in first name and last name field which not look so good.
because name having number in it look like fake details. Which may look like unsafe on site too.

It not look good because name can’t contain number so for validating it just use 'woocommerce_after_checkout_validation ' hook to add custom validation rules and error messages for this.

Example :

function ValidateFirstnameLastname( $fields, $errors ){
  if ( preg_match( '/\\d/', $fields['billing_first_name'] ) || preg_match( '/\\d/', $fields['billing_last_name'] )  ){
    $errors->add('validation','Your First name or Last name contains a number. Really?' );
  }
}
add_action('woocommerce_after_checkout_validation','ValidateFirstnameLastname',99,2);
null

Enjoy

Shiv kumawat

Executive Director & CEO

"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.”

Latest Posts

On-Device AI Mobile Apps 2026 73% Cloud Cost Savings

  On-Device AI Mobile Apps 2026 73% Cloud Cost Savings The $14M GDPR Problem You’re Solving   Fintech firms: Cloud…

Shafeeq Khan
February 18, 2026

Generative AR Shopping Apps 2026 67% Conversion Boost

  AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide) The 73% Cart Abandonment Problem You’re Solving…

Shafeeq Khan
January 31, 2026

AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide)

  AI Agent Mobile Apps 2026 $2.3M ARR in 90 Days (Complete Guide) The $2.3M ARR Problem You’re Solving  …

Shafeeq Khan
January 30, 2026
,

Leave a Reply

Your email address will not be published. Required fields are marked *