I’m trying to use regex to check if a full address string contains a zipcode, can someone help me out?
$address = '10100 Trinity Parkway, 5th Floor Stockton, CA 95219';
if (preg_match('--regex_here--',$ad)) {
echo 'true';
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Generally zip codes follow the two letter state code, so something like the following should be fairly reliable:
Explanation:
You could also change the
\bat the end to$since zip codes are usually (always?) at the end of the address.