Zimi Posted June 19, 2008 Share Posted June 19, 2008 Hello I'm trying to use the eregi function to make sure a string entered by the user is valid (only English letters, numbers, "_" and "-". This is my first time using eregi and regular expressions so I have no idea what's the problem with my code: function Vaild_Login($Login_Name) { if(eregi('[^A-Za-z0-9_-]', $Login_Name)) { return True; } else { return False; } } Any help would be appraised ^^ Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 You put the ^ inside of a character class, making it mean "not". Try this: ^[A-Za-z0-9_-]$ Quote Link to comment Share on other sites More sharing options...
Zimi Posted June 19, 2008 Author Share Posted June 19, 2008 Fast replay lol, thanks ^^ But still not working, the code looks like this: function Vaild_Login($Login_Name) { if(eregi("^[A-Za-z0-9_-]$", $Login_Name)) { return True; } else { return False; } } And the other end: if(Vaild_Login($Login_Name) == False && $Login_name != "") { echo "You have submitted an invaild Login Name"; } Oh, sorry for putting the topic in the wrong place =x Quote Link to comment Share on other sites More sharing options...
Zimi Posted June 19, 2008 Author Share Posted June 19, 2008 Edit: Thanks a lot, got it to work ^^ And sorry for posting this topic in the wrong place. And for quoting instead of editing 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.