note 53931 added to function.preg-match-all

From: Date: Fri, 17 Jun 2005 13:33:17 +0000
Subject: note 53931 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-90583@lists.php.net to get a copy of this message
I was trying to validate users name, password and any other for any funny characters, and took me a bit, but hope this helps u all out, there are many samples where that helped me out, and I am having a hard time trying to understand the pattern syntax and modifies, so I like simple! <?php function isGoodChar($test) { return !preg_match ("/[A-z0-9_]/",$test); } ?> this will test for anything that is not A-Z,a-z,0-9 or _ and return false if it does find something else <?php if (isGoodChar($user_name) == false) { error_(); // <-- what ever error routine u want } ?> ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53931 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53931&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53931&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90583) next »