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
https://forums.phpfreaks.com/topic/187642-old-regex/
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
https://forums.phpfreaks.com/topic/187642-old-regex/#findComment-990689
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.