Custom Validation Rules

Custom validator feature can be used to define custom validation rules using RegEx which can be selected from 'Validations' drop-down when creating or editing checkout fields. To create new custom validators,
  1. Go to Dashboard → WooCommerce → Checkout Form  Advanced Settings page. You can see a section Custom Validators with 4 fields showing Validator Name, Validator Label, Validator Pattern, and Validator Message.
  2. Fill the fields according to your requirements. Enter the regular expression to be validated in the Validator Pattern field.
  3. Click on Add New Validator button to get new validator settings row.
  4. Enter the validator settings.
    • Validator Name: A unique name for the validation rule, which will be used internally to identify the validator.
    • Validator Label: The display name for the validation rule.
    • Validator Pattern: A regular expression which is used to match a valid input. Eg : /^[0-9]{5}$/. The regular expression must be prefixed with /^ and suffixed with $/.
    • Error Message: The message to be displayed when the validation fails. Use %s to include field name in validation messages.
  5. Save Changes.
  6. Newly created validators will be available to choose in Validations drop-down.
  7. Done.

VIDEO TUTORIALS: