-2

I've been looking on internet without finding answers to my problem. I want that the user enter a login to create his account, but I need to check if there is any punctuation or accentued characters in the login name. To sum up I only want this kind of characters: [0-9] or [a-z] or [A-Z] or any asian characters except asian punctuations.

What I've been thinking was to do a loop on my string and to look if the actual character is equal to a pronunciation or accentued characters but there are so many punctuations and accentued characters that it would take me a long time to write them all. And the fact is I don't know all the punctuations characters used in the asian writing system.

Do you have any idea about what should I do ? Thank you !

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
aoilotr
  • 1
  • 1
  • Take a look at http://stackoverflow.com/questions/4923319/php-check-if-the-string-has-chinese-chars. – chris85 Sep 18 '16 at 17:27

1 Answers1

0

You meant, you want to allow only alphanumeric characters? If so, use regular expression. See sample code below.

if( preg_match('/^[a-z0-9.,!?:;"-_\']+$/i', $str)){ // Remove unwanted chars if you don't need to include all 
    echo 'Success';
}else{
    echo 'Error!';
}

See this documentation for more details. http://php.net/manual/en/function.preg-match.php http://www.phpforkids.com/php/php-functions-regular-expressions.php

Saji
  • 1,374
  • 1
  • 12
  • 19