How do I ereg to check and see if a string matches this format:
city, state zip ie: Beverly Hills, CA 90210
The zip code can be 5 digits or 9 digits?
Anybody know?
if(!eregi('[a-zA-Z ]+,[A-Z]{2}[[:blank:]][0-9]{5}$',"Beverly Hills,CA 90210")){ echo "wrong"; } else{ echo "correct"; } i can't realize 5 digits or 9 digits,sorry!
or use: if(!eregi('([a-zA-Z ]+,[A-Z]{2}[[:blank:]][0-9]{5}$)|([a-zA-Z ]+,[A-Z]{2}[[:blank:]][0-9]{9}$)',"Beverly Hills,CA 902101234")){ echo "wrong"; } else{ echo "correct"; } i found it works