Regular Expressions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all

Hopefully a nice easy one :o)

I've got a table with a list of 'installers'.  I have a form for
visitors to find an installer in their area searchning on post code.

Let's say we have installers in:

RG (Reading)
G (Glasgow)

The page tells the vistor to type in the first letter(s) of their post
code.  So, if a visitor types in their postcode as RG23 1TQ, it works.  
If they type in G23 1TQ then it doesn't.  If they type in just G - as
instructed - then it works.

I've just chopped off all but the first 2 digits of whatever they type
in (RG or G2).  What I would like to do is (In pigeon PHP):

If characters one and two are letters, use this for the search.

If character one is a letter and character two is a number then just
chop the first character off and use it for the search.

elseif display error.

What I can't get my head round is the logic and regular expressions
behind this.

Could someone throw me a lifeline please.



Re: Regular Expressions

Andy Jacobs wrote:

Quoted text here. Click to load it

Grab the first 2 characters (if the entry is 2 or more characters)

replace digit with "" (Nothing)


Re: Regular Expressions

 .oO(Andy Jacobs)

Quoted text here. Click to load it

if (preg_match('#^[a-z]#i', $yourString, $result)) {
  // use $result[0] for search
} else {
  // error handling


Site Timeline