ereg function problem

Discussion in 'PHP' started by tech_tycoon, Aug 16, 2010.

  1. #1
    $text=" this is test characters - and ,";

    if (ereg(^[A-Za-Z0-9_ -,)){
    echo "error message"
    }
    When i am testing this function for comma (',') symbol this is not working.Only i am having prblem with comma.Is ereg not work for "," ?
     
    tech_tycoon, Aug 16, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Im not the best with regex but try
    
    if (ereg('[^A-Za-z0-9_,\-]',$text)){
    //any character that is not alphanumeric, underscore, comma, or hyphen
    echo "error message";
    }
    
    PHP:
     
    Last edited: Aug 16, 2010
    Narrator, Aug 16, 2010 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Stop using ereg* functions. They're very insecure and deprecated. Use preg_match() instead.

    And it's unclear what you're trying to do. Do you want to check if any of those characters are in the string? Or at the beginning of the string? Because that's what the ^ at the beginning of the pattern means.
     
    nico_swd, Aug 17, 2010 IP
  4. Googl

    Googl Active Member

    Messages:
    509
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    75
    #4
    [^A-Za-z0-9_,\-]
     
    Googl, Aug 17, 2010 IP