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 ^^ Link to comment https://forums.phpfreaks.com/topic/110992-need-help-with-eregi-function/ 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_-]$ Link to comment https://forums.phpfreaks.com/topic/110992-need-help-with-eregi-function/#findComment-569488 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 Link to comment https://forums.phpfreaks.com/topic/110992-need-help-with-eregi-function/#findComment-569509 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 Link to comment https://forums.phpfreaks.com/topic/110992-need-help-with-eregi-function/#findComment-569521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.