| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | PHP invalid characters Just a quicko, how can I define invalid characters for a user's input so that when a user registers to my site, they don't select a username such as: "#~@L@N J0N3S~#" lol, excuse the example. I only really want letters, numbers and hyphens to be used. Thanks
__________________ Encenta - Amazon Associates CMS |
| |
| | #2 (permalink) |
| Account Closed Join Date: May 2004 Location: /etc/passwd
Posts: 2,178
![]() ![]() ![]() ![]() ![]() ![]() | http://us2.php.net/ctype_alpha I use these functions, but i have a class that i use them, but return false if its empty. I will think about posting it or not ![]() ????: NamePros.com http://www.namepros.com/programming/124238-php-invalid-characters.html Here it is... heh PHP Code:
Last edited by axilant; 09-16-2005 at 01:28 PM.
|
| |
| | THREAD STARTER #3 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Thanks very much for the help
__________________ Encenta - Amazon Associates CMS |
| |
| | #4 (permalink) |
| NamePros Regular Join Date: Jun 2004
Posts: 587
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You should also be able to do a POSIX match. Something like this should work too: PHP Code: -Bob
__________________ Can't wait to be out of this forsaken business. Getting close! :) |
| |
| | THREAD STARTER #5 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Thanks Bob, I am currently using PHP Code:
__________________ Encenta - Amazon Associates CMS |
| |
| | #6 (permalink) |
| Domains my Dominion Join Date: Aug 2005 Location: Web 1.0
Posts: 9,552
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I do like Bob suggested. A regular expression is fine and more flexible IMO. For example I use code like this to test a user name, that means only letters and figures are allowed and the string must be between 4 and 16 chars long. It does the job nicely ![]() PHP Code: |
| |
| | THREAD STARTER #7 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | sdsinc, I just changed my code to the code you posted. But how do I make it case sensitive?
__________________ Encenta - Amazon Associates CMS |
| |
| | THREAD STARTER #9 (permalink) |
| SQLdumpster.com Join Date: Jun 2005 Location: West Sussex, UK
Posts: 573
![]() ![]() | Ah, simple as that eh? Thanks a lot
__________________ Encenta - Amazon Associates CMS |
| |
| | #10 (permalink) |
| A Wealth of Knowledge Join Date: Aug 2004
Posts: 3,809
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I use eregi a lot when validating email addresses and other forms of data - very useful. If you want to see other ways it can be used, check out the PHP Manual documentation http://us2.php.net/eregi -Steve |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tutorial: Getting started with PHP (The Basics) | deadserious | Webmaster Tutorials | 60 | 11-17-2007 12:35 PM |
| Googlism - What does google think of you? | deadserious | The Break Room | 55 | 12-15-2005 10:09 AM |
| Seeking php function to strip invalid characters from string | RJ | Programming | 9 | 04-01-2005 12:34 AM |