+ Reply to Thread
Results 1 to 4 of 4

Thread: preg_match/if statements, can't quite grasp it...

  1. #1
    jbdesign's Avatar
    jbdesign is offline x10Hosting Member jbdesign is an unknown quantity at this point
    Join Date
    Mar 2009
    Location
    Nampa, ID, USA
    Posts
    26

    preg_match/if statements, can't quite grasp it...

    I'm trying to write an if statement that tests/validates a field that has a two word name, for example New York. I just can't seem to figure out how to do it. I mean was able to write perfectly working if statements to test/validate email addresses, US zip codes, state abbreviations, and so on, I just can't seem to understand getting an if statement that checks for two word names!

    Any help would be appreciated.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: preg_match/if statements, can't quite grasp it...

    When asking about code, post short samples (minimal test cases, actually). Without this, it's hard to help you with mistakes you might be making. Also, describe the overall goal (why are you trying to do whatever it is?) in addition to the specific task. Sometimes there's a better way of achieving the goal, obviating your question.

    REs to match a string containing exactly two words:
    /^\W+(\w+\W+){2}$/
    If you want to restrict strings to word characters and spaces:
    /^\s+(\w+\s+){2}$/
    If you don't want leading or trailing spaces:
    /^\w+\s+\w+$/
    Last edited by misson; 05-26-2009 at 08:53 PM.

  3. #3
    jbdesign's Avatar
    jbdesign is offline x10Hosting Member jbdesign is an unknown quantity at this point
    Join Date
    Mar 2009
    Location
    Nampa, ID, USA
    Posts
    26

    Re: preg_match/if statements, can't quite grasp it...

    I do apologize for not providing an example or what exactly my desired end result(s) are.

    Your re examples were more then helpful and I was able to pinpoint where I was going wrong.

    Thank you again fro your help!

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: preg_match/if statements, can't quite grasp it...

    This post was originally an accidental duplicate. It's now marked for deletion.
    Last edited by misson; 05-26-2009 at 08:54 PM.

+ Reply to Thread

Similar Threads

  1. Replies: 11
    Last Post: 08-27-2006, 05:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers