Jezza Posted January 11, 2010 Share Posted January 11, 2010 Hi I want to be able to check addresses, for example it checks if the street address is valid. "123 Test street" I need to know how to check if the string contains a number then a space then a letter in one. "<number><space><letter>" is there anything that can do that? I heard about preg_match but that thing confuses me. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 11, 2010 Share Posted January 11, 2010 Well, this will do what you ask: if(preg_match('/^\d+ [a-z]/i', $address)<1) { echo "Invalid"; } else { echo "Valid"; } But, that may be too strict. What is the address is "5200 1st Street" To allow the first character after the space to be a letter or a number use this preg_match('/^\d+ [a-z\d]/i', $address) Quote Link to comment Share on other sites More sharing options...
Jezza Posted January 11, 2010 Author Share Posted January 11, 2010 Thanks a bunch for your help, preg_match is really kool. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.