Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Regular Expressions help

    I have a form that validates each field before it can be submitted using regular expressions. I also have an unordered list that returns different error messages based on what the regular expressions evaluate to. What I would like to do is create a different error message when a field is blank vs. when it contains invalid characters. Here is the relevant code that I have right now:

    PHP Code:
    $firstNameError=0;

    if (!
    eregi("^[[:alpha:]]+$"$firstName)) {$firstNameError=1
    What I thought I should do is create an if statement that reads:

    PHP Code:
    if ($firstName=="") {create separate error message
    However that will not work since the first if statement also tests for at least one character. I could create a regular expression that tests for the presence of every character other than letters, but that seems like a ridiculous thing to do. Any help is appreciated.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Check for blanks before your regex.

    if(blank condition)
    {

    }
    elseif(regex condition)
    {

    }

    If the blank condition returns true the regex won't ever be run.

    Good luck;

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    good way to check if blank is either of:

    is_empty()
    isset()
    $var == ""

    Hope that helps you with the above.
    PHP / CSS / Perl / XML / XHTML

    For cheap ipod touch go to protella.com

  • #4
    New Coder
    Join Date
    Feb 2007
    Location
    Albany, Oregon
    Posts
    66
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Why didn't I think of that? Thanks for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •