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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.