Jump to content

Checking Patterns


Jezza

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/188013-checking-patterns/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/188013-checking-patterns/#findComment-992608
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.