Vivid Lust Posted January 27, 2010 Share Posted January 27, 2010 Could someone please help me with regular expressions? I'm writing a function to check if a username is valid, it can only contain letters and underscores, this is what i wrote: function isValidUsername($TargetUsername){ if( !preg_match("/^[A-Za-z]_$/", $TargetUsername) ){ return false; }else{ return true; } } Is it correct? It always returns false .. if for example, the input is "abc" it returns false which isnt what i want it to do ! Please help!! thanks. Link to comment https://forums.phpfreaks.com/topic/189996-regular-expressions-to-validate-username-allow-only-letters-and-_/ Share on other sites More sharing options...
salathe Posted January 27, 2010 Share Posted January 27, 2010 Move the underscore (_) one character to the left and put a plus symbol (+) where it was. Then tell my why that would work. Link to comment https://forums.phpfreaks.com/topic/189996-regular-expressions-to-validate-username-allow-only-letters-and-_/#findComment-1002396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.