#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Error in the expression?


    This script should check if there are any "bad" characters, i.e. if an attack is being commenced:



    PHP Code:
    $string_exp "/^[- ,.A-Za-zА-Яа-я0-9]+$/";
    if(!
    preg_match($string_exp,$tour_title)) { 
        
    $error_message .= '<li>Bad data in one the "tour_desc" field.</li>'
      } 
    Then, if $error_message contains anything, an error message should be displayed instead of sending an email.

    I suppose that is the string contains only latin symbols, cyrillic symbols, numbers, comma, dot, space or "-", the check should be OK and the email should be sent. But in reality it seems so that the test gives an error depending on what cyrillic symbols are there in the string.

    I tried some examples:

    Syntax: [ Download ] [ Hide ] [ Select ]
    abvgd
    абвгд
    Абвгда
    АбрикосыАпельсины
    Абрикосы
    Абр


    and some of them work and some don't.

    Could anybody point me at the problem please?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    This worked in my test:
    Code:
    if (preg_match('/^[- ,.A-Za-zА-Яа-я0-9]+$/', $test)) {
      #matches
    } else {
      #does not match
    }
    
    Matches these:
    abvgd
    абвгд
    Абвгда
    АбрикосыАпельсины
    Абрикосы
    Абр

IMN logo majestic logo threadwatch logo seochat tools logo