Custom Form Validation
-
Hello, a few years ago someone added code to our website, which validates a field against a prefix and field length.
The field validation code looks like this:
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { if ((substr($_POST['billing_manr'],0,3) <> "MA-") || (strlen($_POST['billing_manr']) <> 9)) wc_add_notice( __( 'Error code ...' ), 'error' ); }
It validates against MA- and an allover length of 9 letters. For example, MA-123123 is OK, MA-123 isn’t.
Now we want to validate against MA-xxxxxx and BW-xxxxxx but I’m not sure how the correct syntax is.
I tried already the following:
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { if ((substr($_POST['billing_manr'],0,3) <> "MA-") || (substr($_POST['billing_manr'],0,3) <> "BW-") || (strlen($_POST['billing_manr']) <> 9)) wc_add_notice( __( 'Error code ...' ), 'error' ); }
But with this the validation fails again both, MA- and BW-.
Can someone help me with this? Thanks and best regards!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Form Validation’ is closed to new replies.