note 51204 deleted from function.preg-match by nlopess

From: Date: Thu, 24 Mar 2005 23:28:55 +0000
Subject: note 51204 deleted from function.preg-match by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-86920@lists.php.net to get a copy of this message
Note Submitter: Sandra Hennig (snadra <at> snadra.de) ---- If you want to match all alphanumerical characters plus special chars (umlauts) from several languages, the following might be a better solution, than writing a huge regex wich covers all special chars you need. Covering several languages at once can be interesting for name fields for example or for multilingual websites (someone has a name with a swedish special char and he wants to fill out a german form with validation on it). This example covers all special chars of German, Dutch, French, Portugese, Spanish, Danish, Finnish, Norwegian and Swedish: // use setlocale (as mentioned above by reiner keller), but assign several language codes to it: setlocale (LC_ALL, 'de_DE', 'nl_NL', 'fr_FR', 'pt_PT', 'es_ES', 'da_DK', 'fi_FI', 'no_NO', 'sv_SV'); // a form was send: if (preg_match("/^[[:alpha:]]+$/",$_POST['field'])) { echo "<br>matches"; } else { echo "<br>does not match"; } I tested this code on SuSE9.1 only. On a different system, the language codes might be a little different.

« previous php.notes (#86920) next »