• Resolved diegpl

    (@diegpl)


    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

    (@themehigh)

    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

    (@diegpl)

    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 5 years, 3 months ago by diegpl.
    • This reply was modified 5 years, 3 months ago by diegpl.
    Plugin Author ThemeHigh

    (@themehigh)

    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.