Need help w/ error checking of text input field

Discussion in 'PHP' started by PGriff, Mar 15, 2011.

  1. #1
    I'm trying to figure out why all input is generating a "Directions not alphanumeric" error. The $subdirections variable should contain the text input:

    /* Check if directions is not alphanumeric */
    else if(!eregi("^([0-9a-z])+$", $subdirections)){
    $form->setError($field, "* Directions not alphanumeric");
    }

    Thanks for any tips.
     
    PGriff, Mar 15, 2011 IP
  2. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Works just fine on my server. Can you show us an example of input data you are testing this with ?
     
    Minimal Hank, Mar 15, 2011 IP
  3. awood969

    awood969 Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    40
    #3
    ereg has been depreciated for a while now. Use preg_match() instead for all REGEX functionality in PHP. I believe thats correct as of 5.3 (poss 5.2)

    Thanks
    Andrew
     
    awood969, Mar 16, 2011 IP
  4. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes use preg_match() otherwise your script looks fine
     
    srisen2, Mar 16, 2011 IP
  5. PGriff

    PGriff Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks. Sorry about the slow response. I think the problem is whitespaces. i'll try preg_match(). I was also looking at ctype_alnum.
     
    PGriff, Mar 18, 2011 IP
  6. vediovis

    vediovis Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    preg_match()
     
    vediovis, Mar 22, 2011 IP