Jump to content

preg_match excluded characters


tkm76

Recommended Posts

Hi everybody!

 

I'm having a bit of a problem with preg_match. I've spent two days on this, tried dozens of ways, nothing worked. So I decided to join this forum. OK, my problem is in these lines of code:

 

if (!preg_match("/^[a-zA-Z0-9_\-\.]*$/", $username)){

echo "Username contains excluded characters!";

exit;

}

 

I'm making a registration form, and I want to allow following types of registration: "john_doe", "john-doe" and "john.doe". Besides "johndoe". Case sensitivity and numbers are also included. Everything other than that should be considered as excluded. I somehow managed to register two dummy records as it is. But after that it started giving me that echo message" Username contains excluded characters!" if i DON'T user those three special characters as well! And that shouldn't be a condition, but an option. How do I solve this problem? I would be grateful if someone would correct me in whatever I'm doing wrong. Thanks in advance!

 

T.K.M.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.