1

Im validating a form and its easy to validate numbers, letters a-z and so on but when i got to the point where i need to validate a field which must contain only the characters (a-z and special characters such as öçğüiş) with at least one space only I am really stuck!

I tried the following and some other techniques without success:

function validateAlphaSpecial($value) {
    if (ereg("/^[\p{L}\s]+$/", $value, $regs)) {
           echo 'true';
         } else {
           echo 'false';
        } 
}

Has anyone got a solution for this. Thank you.

London Boy
  • 387
  • 1
  • 4
  • 14
  • [ereg has been deprecated](http://php.net/manual/en/function.ereg.php). Have you considered [PCRE](http://php.net/manual/en/book.pcre.php)? – cmbuckley Mar 30 '12 at 22:36
  • Ereg has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. – ajreal Mar 30 '12 at 22:36
  • i never used such chars in regex match, but i heard that ereg is going to be deprecated – kappa Mar 30 '12 at 22:38
  • `Ereg` isn't going anywhere, deprecated or not. But you're already using a `preg_match` regex and meta patterns. So just use the right function. – mario Mar 30 '12 at 22:39

1 Answers1

0

Ereg has been deprecated as of PHP 5.3.0 like others said and you shouldn't use EREG.

The snippet below fits your validating requirement: a-z and special characters such as öçğüiş with at least ONE SPACE.

if( preg_match("/[\p{L}]\s{1,}+/u", $value) > 0 ) {
    echo 'Valid';
} else {
    echo 'Not valid';
}

About /u modifier [ from documentation ] :

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8.

edigu
  • 9,878
  • 5
  • 57
  • 80