icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » eregi problem

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old October 24th, 2004, 6:50 PM   #1 (permalink)
Registered User
Seasoned Poster
 
BloodSeaker's Avatar
 
Joined in Dec 2003
Hosted on Mango
85 posts
Gave thanks: 0
Thanked 0 times
eregi problem

Hi, I want to check a username on its input.

It may only contain numbers or a-z and the chars _ and -

My code for this is

if( !eregi("[a-zA-Z0-9_-]*", $username){
//print error
}

But this line of code always returns 1
If I enter the username fred (which is allowed) or if I enter fred+derb

All is allowed

Does anyone canhelp me on this one, cause I can't find the problem in here :s
__________________
SH57 server - zwammers.com
Pass16 server - bloodseaker.be
BloodSeaker is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old October 26th, 2004, 12:37 AM   #2 (permalink)
Third Plateau
Comfy Contributor
 
Dave's Avatar
 
Joined in Apr 2004
Lives in East Hanover, New Jersey
Hosted on Nifty
272 posts
Gave thanks: 0
Thanked 0 times
Quote:
Originally Posted by BloodSeaker
if( !eregi("[a-zA-Z0-9_-]*", $username){
//print error
}
The * means match 0 or more times. You should make it:
^[a-zA-Z0-9_-]+$

The + makes it match once or more, and the ^ sets the beginning of the line and the $ sets the end.
__________________
site (syberdave.net) - server (nifty)
Dave is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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