Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-07-2005, 02:34 PM registering?
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
i have a site that users can register with, how do i stop people from entering things like " . ' @ # £ etc in their usernames?
timsquash5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-07-2005, 08:54 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
This regex ought to do it:

PHP Code:

$username 
$_POST['username'];

$usernamepreg_replace("#[^A-Za-z0-9]#","",$username); 
Brief explanation:

Preg_replace looks for things that match the regex, replaces them with the second string argument (in this case "" the empty string). The string it does the replacement on is the third argument, in this case our username.

The regex includes a single character class denoted by the square brackets. It includes only letters and numbers. The first character in the class is '^' which when placed at the start will invert the character class (so it matches everything except letters and numbers).

So you have a regex that matches everything but letters and numbers, and then replaces them with "", leaving you with just letters and numbers in the original username. If you want to allow certain characters like _, you just add them between the [] as long as the ^ stays at the start, e.g #[^A-Za-z0-9_]#

The #s just mark the start and end of the regex.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-07-2005, 09:24 PM
Webmaster Talker

Posts: 589
Trades: 0
Thank you oberon.
thevirus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to registering?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11450 seconds with 12 queries