Jump to content

[SOLVED] Regular Expressions


chriskiely

Recommended Posts

Hello, I am writing a form validation script in php and have got the whole thing working except for checking to see if the username supplied by the user is in the correct format (i.e. contains only letters, numbers and the underscore character). This the code I have come up with but it always produces the error message. I have to say I don't really understand the syntax for creating regular expressions so I am assuming this is where I am going wrong. ($user_name is passed from the form)

 

$user_name=stripslashes($user_name);

$user_name=trim($user_name);

$user_name=strtolower($user_name);

 

if(!eregi("^[A-Za-z0-9\_$", $user_name)){

    $errmsg.='Invalid user name, please try again.';

}

 

Any help would be really appreciated as this is driving me mental!!

Thanks, Chris

Link to comment
https://forums.phpfreaks.com/topic/50521-solved-regular-expressions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.