Title: Custom validation rules using RegEx
Last modified: December 5, 2019

---

# Custom validation rules using RegEx

 *  Resolved [diegpl](https://wordpress.org/support/users/diegpl/)
 * (@diegpl)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-rules-using-regex/)
 * Hi, on pro version plugins ad description inside wp editor is written “custom
   validation rules using RegEx”. So, with that I could set a required number that
   always starts with “300” and a specific characters number for example? Tks!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-rules-using-regex/#post-12210813)
 * As per the WordPress forum policy, we can’t answer premium related questions 
   on this forum. Could you please raise a ticket through our website so that our
   technical team will be able to help you.
 * Thank you!
 *  Thread Starter [diegpl](https://wordpress.org/support/users/diegpl/)
 * (@diegpl)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-rules-using-regex/#post-12224363)
 * Ok, I just sent u a message. I really would like to be able to do that through
   your plugin, since my client would be able to manage that by himself. However,
   I also would like to know how to do that through php. I do not know if that is
   on your scope, so here is the code, which is not working, do you know tell me
   why?
 *     ```
       //https://rudrastyh.com/woocommerce/custom-checkout-validation.html - hook woocommerce_after_checkout_validation did not work
       //https://stackoverflow.com/questions/28603144/custom-validation-of-woocommerce-checkout-fields
       add_action( 'woocommerce_after_checkout_validation', 'misha_validate_fname_lname', 10, 2);
   
       function misha_validate_fname_lname( $fields, $errors ){
   
           if ( strpos( $fields[ 'billing_n_matricula' ], 300) === false   ){
               $errors->add( 'validation', 'Seu número de matrícula parece estar errado, favor digitar o correto.' );
           }
       }
       ```
   
 * It seems the code runs, since I see the validation warning, but it never gets
   true, to go ahead. Tks!
    -  This reply was modified 6 years, 6 months ago by [diegpl](https://wordpress.org/support/users/diegpl/).
    -  This reply was modified 6 years, 6 months ago by [diegpl](https://wordpress.org/support/users/diegpl/).
 *  Plugin Author [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * (@themehigh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-rules-using-regex/#post-12233904)
 * We have checked the code in detail. The issue is that, the second argument for
   the _**strpos**_ will be a string type. Here in the code it is used as an integer
   type. Please change the code as per the below snippets.
 *     ```
       add_action( 'woocommerce_after_checkout_validation', 'misha_validate_fname_lname', 11, 2);
       function misha_validate_fname_lname( $fields, $errors ){
           if ( strpos( $fields[ 'billing_n_matricula' ], '300') === false   ){
               $errors->add( 'validation', 'Seu número de matrícula parece estar errado, favor digitar o correto.' );
           }
       }
       ```
   
 * Hope this will help 🙂
 * Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom validation rules using RegEx’ is closed to new replies.

 * ![](https://ps.w.org/woo-checkout-field-editor-pro/assets/icon-256x256.gif?rev
   =3479964)
 * [Checkout Field Editor (Checkout Manager) for WooCommerce](https://wordpress.org/plugins/woo-checkout-field-editor-pro/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-checkout-field-editor-pro/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-checkout-field-editor-pro/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-checkout-field-editor-pro/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-checkout-field-editor-pro/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-checkout-field-editor-pro/reviews/)

## Tags

 * [premium version](https://wordpress.org/support/topic-tag/premium-version/)
 * [pro version](https://wordpress.org/support/topic-tag/pro-version/)

 * 3 replies
 * 2 participants
 * Last reply from: [ThemeHigh](https://wordpress.org/support/users/themehigh/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-rules-using-regex/#post-12233904)
 * Status: resolved