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

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, the Jaipur-based IT company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

Colour photograph illustrating the Eoxys blog post 'Google Preferred Sources: Get Your Site Picked in AI Mode', used as the featured image for google preferred sources.

Google Preferred Sources: Get Your Site Picked in AI Mode

Google lets people pick the news and content sites they want to see more of. When someone picks yours, your…

Shafeeq Khan
November 17, 2026
Colour photograph illustrating the Eoxys blog post 'Computer-Use AI Agents: Automate Old Software Without an API', used as the featured image for computer use ai agents.

Computer-Use AI Agents: Automate Old Software Without an API

Every business has a task like this: an employee logs into a government portal, a supplier site or a 15-year-old…

Shafeeq Khan
November 16, 2026
Colour photograph illustrating the Eoxys blog post 'Product Feed Optimization for ChatGPT Shopping and AI Mode', used as the featured image for product feed optimization ai shopping.

Product Feed Optimization for ChatGPT Shopping and AI Mode

When a shopper asks ChatGPT or Google AI Mode for “the best running shoes under ₹6,000 for flat feet”, the…

Shafeeq Khan
November 15, 2026
,

Leave a Reply

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