0

I'm a newbie in PHP, I use this PHP code that works like a charm. It's a custom form that sends to Woocommerce different fields. I want to add a "preg_match" check for each of those fields so the user can only enter:

    $address = array(
        'first_name' => $first_name,
        'last_name'  => $last_name,
        'company'    => '',
        'email'      => $email,
        'phone'      => $phone,
        'address_1'  => $street,
        'city'       => $city,
        'state'      => '',
        'postcode'   => $postcode,
        'country'    => $country,
    );

In the telephone field: numbers, "+", spaces; (22 burns absolute) In the postcode field: postcodes are contained in a custom post type "Structures" with their titles as values. Just those qualities. How would I do that?

3
  • 2
    you might be better asking this on stackoverflow, it's possible to rewrite this question to include no references to WordPress and a simplified pure PHP example, e.g. "Given a variable, how do I validate that it contains a phone number? I heard pre_match could help but I can't find examples"
    – Tom J Nowell
    Commented Jun 22, 2022 at 10:09
  • 1
    also note that $_SESSION doesn't work on a lot of WordPress hosts, and has security issues that require extra steps to be taken. It's much easier and simpler to use cookies instead
    – Tom J Nowell
    Commented Jun 22, 2022 at 10:09
  • Thank you so much for letting me know
    – Nasya
    Commented Jun 22, 2022 at 10:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.