dear all,
i am facing a problem. actually i wanna get user validation with the following code, I want to insert only [a-z0-9_] character in user login....when i insert username like this 'asdfdfad' it returns else part ( special characters are not allowed ). please solve it ..... thanks

if ( preg_match ('/^[a-z0-9]$/', $username)) {
    echo $username. ' ' . $password . ' ' . $email;     
}
else {
    echo 'special characters are not allowed';
}

Your pattern matches only a single character, add a + to match one or more characters:

if ( preg_match ('/^[a-z0-9]+$/', $username)) {
    echo $username. ' ' . $password . ' ' . $email;     
}
else {
    echo 'special characters are not allowed';
}

I suggest using a tool like RegexBuddy to help write and test regular expressions.

commented: +1 for RegexBuddy +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.