PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Oct 23, 2018 6:52 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Apr 17, 2012 1:36 am 
Offline
Forum Newbie

Joined: Tue Apr 17, 2012 1:21 am
Posts: 3
Hi

I check username in my login page with following code that it allow to have a username with numbers and letters and _ only!

Syntax: [ Download ] [ Hide ]
$user=preg_replace("([^a-z0-9_]*)",'',$user);


now,I want to forbid users to have a username with other characters in my register page and I want to check it with preg_match function,but I don't know what regular expression is suitable for it!please help me!

thanks


Top
 Profile  
 
PostPosted: Tue Apr 17, 2012 7:02 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Code:
/[^a-z0-9_]/

Use that with preg_match. If it matches then the username is invalid.


Last edited by requinix on Tue Apr 17, 2012 11:52 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Tue Apr 17, 2012 10:25 am 
Offline
Forum Newbie

Joined: Tue Apr 17, 2012 1:21 am
Posts: 3
it is not that expression i need it.I want an expression that find every character in a string except small letters,numbers,and _.
because username must has a small letters,numbers,_. and other things will be replaced with above code.
users can select a username with small letters,numbers,_.i want to find other characters in usernames and send error message to users.


Top
 Profile  
 
PostPosted: Tue Apr 17, 2012 11:54 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
There was a typo: missed out on the ^.

So you actually want to know every single invalid character in the username? Same expression still, just give it to preg_match_all().
Or if you only care about knowing whether the username is invalid at all - whether it contains anything that's not a letter, number, or underscore - then it's still that expression.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group