Solved

How to allow in login only 0-9, a-z, A-Z, _ signs ONLY?

Posted on 2009-07-14
3
283 Views
Last Modified: 2013-12-13
as topic (php)
0
Comment
Question by:AndyPSV
3 Comments
 
LVL 13

Expert Comment

by:marchent
ID: 24852457
if( preg_match('/^\w+$/',  trim($user_name) ) ){
     // process
}
0
 
LVL 9

Accepted Solution

by:
xBellox earned 500 total points
ID: 24852465
This should work:

if( preg_match( "/^[A-Za-z0-9_]+$/", $login ) ) {

    echo "Login ok";

} else {

    echo "Bad login";

}

Open in new window

0
 

Author Closing Comment

by:AndyPSV
ID: 31603400
thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now