Jump to content

Old regex


corrupshun

Recommended Posts

just read an article on regex stuff, found out how to use it then realize it's depricated...

I finally felt like i understood it!

function validate_user() {
if(eregi('^([a-zA-Z0-9._-]{4,12})$', $_POST['username'])) {
echo "username legit";
}
else {
echo "Username contains invalid characters.";
}
}

how could I take this and make it into preg_match?

Also tell me how you changed it :P

Link to comment
Share on other sites

The only thing you need is to add a pair of pattern delimiters (I most often use the tilde ~) and the pattern modifier i, making the search case insensitive (to achieve the same effect as eregi() - but that won't have any actual effect with the current pattern, since both a-z and A-Z are included. In the pattern below I've removed A-Z and added the i). I would also add the pattern modifier D, to make the dollar sign really mean end of string (read here).

 

~^[a-z0-9._-]{4,12}$~iD

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.