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?

New contributor
Nasya is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
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
    Jun 22 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
    Jun 22 at 10:09
  • Thank you so much for letting me know
    – Nasya
    Jun 22 at 10:38

0

Your Answer

Nasya is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.