note 56092 deleted from function.preg-match by jome
| From: | jome@php.net | Date: | Fri, 30 Sep 2005 19:04:56 +0000 |
| Subject: | note 56092 deleted from function.preg-match by jome | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96082@lists.php.net to get a copy of this message | ||
Note Submitter: paul at sysnyx dot com
----
When creating a membership registration form, certain charactors needed to be excluded from the
"username" field, and only allowed specific charactors.
After viewing a few examples on here, I had only found this to work correctly:
if(!preg_match("/^[a-z0-9][\w.-]*$/i",$post[user])):
execute code if the field includes charactors not allowed
endif;
(note: $post[user]=$_POST['user'];)
This code allows . _ - but not at the beginning of the username field. After trying several
examples, most examples allowed the use of an unallowed charactor at the beginning of the text.
Which gave the user the ability to use something such as "__username".
Another example listed on here had the syntax /[^a-z0-9] - which allowed users to use
"^username".
This code allows a number to be in the beginning of the text and stops users from using unallowed
charactors, even in the beginning of the text.