note 56092 added to function.preg-match

From: Date: Tue, 23 Aug 2005 09:38:30 +0000
Subject: note 56092 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-94071@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56092 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56092&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56092&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94071) next »