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 and GenAI development company he has led since 2009. Eoxys builds custom AI, web and mobile applications for businesses worldwide. Shiv writes about AI app development, generative AI for business, and building software products that deliver real results. Connect with him on LinkedIn: https://www.linkedin.com/in/shiv-kumawat-eoxys/

Latest Posts

Siri AI integration for iOS apps: isometric illustration of an iPhone app connected to a glowing assistant orb and app action tiles

Siri AI Integration for iOS Apps: How to Get Your App Ready

Siri AI started rolling out in mid-September with iOS 27, and it can now find content inside apps and act…

Shiv Kumawat
October 8, 2026
Isometric illustration of an online store connected to three AI shopping agents handling product discovery, chat and checkout

AI Shopping Agents for E-commerce: Get Your Store Ready Now

This is the first holiday season where AI shopping agents are a real sales channel. Shopify’s 2026 holiday research, published…

Shiv Kumawat
October 7, 2026
Build vs buy AI hiring software: custom-built blocks versus a ready-made hiring dashboard, balanced by AI

Build vs Buy AI Hiring Software: A 2026 Decision Guide

Recruiting is where most companies meet AI first. In SHRM’s 2025 Talent Trends research, 51% of organizations said they use…

Shiv Kumawat
October 6, 2026
,

Leave a Reply

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