note 51204 added to function.preg-match
| From: | (snadra<at>snadra.de) | Date: | Wed, 23 Mar 2005 13:32:18 +0000 |
| Subject: | note 51204 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86842@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51204
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51204&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51204&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51204&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51204&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51204&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51204&report=yes
Search -- http://master.php.net/manage/user-notes.php