corrupshun Posted January 7, 2010 Share Posted January 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
thebadbad Posted January 7, 2010 Share Posted January 7, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.