xProteuSx Posted December 21, 2007 Share Posted December 21, 2007 What would be an 'eregi()' pattern for a string that is: - alphanumeric - 4-12 characters I'm a little confused?? My book is only for PHP version 4. Most online resources are useless. Would this be it? eregi([a-z]+[A-Z]+[0-9]+{4,12},$string) Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/ Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 I don't know about ereg but preg would be equivalent would be preg_match("/[a-zA-Z0-9]{4,12}/i",$string) Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-420298 Share on other sites More sharing options...
xProteuSx Posted December 21, 2007 Author Share Posted December 21, 2007 So are you saying that something like this would work? if (!preg_match("/[a-zA-Z0-9]{4,12}/i",$string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-420300 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 Yep that would do Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-420302 Share on other sites More sharing options...
Dragen Posted December 21, 2007 Share Posted December 21, 2007 I believe the ereg would be: if (!eregi("^[a-z0-9]{4,12}4", $string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } which is pretty similar. I think preg_match is supposed to be quicker anyway. Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-420857 Share on other sites More sharing options...
xProteuSx Posted December 26, 2007 Author Share Posted December 26, 2007 When you use the following code: if (!eregi("^[a-z0-9]{4,12}4", $string) What does the second '4' mean? The one here >> }4" << Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423657 Share on other sites More sharing options...
xProteuSx Posted December 26, 2007 Author Share Posted December 26, 2007 Also, I with this string, does it accept upper case characters? if (!eregi("^[a-z0-9]{4,12}4", $string)) or do I have to do this: if (!eregi("^[a-zA-Z0-9]{4,12}4", $string)) ?? Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423666 Share on other sites More sharing options...
Dragen Posted December 26, 2007 Share Posted December 26, 2007 sorry the four was supposed to be a $. Yes it's not case sensitive as it's using 'eregi', not 'ereg' if (!eregi("^[a-z0-9]{4,12}$", $string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } if you want only lower case use this: if (!ereg("^[a-z0-9]{4,12}$", $string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } or for only caps switch the a-z, with A-Z Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423680 Share on other sites More sharing options...
xProteuSx Posted December 26, 2007 Author Share Posted December 26, 2007 For those who are following this thread ... If you can't get this to work: if (!ereg("^[a-zA-Z0-9]{4,12}$", $string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } This should fix it: if (!ereg("^([a-zA-Z0-9]){4,12}$", $string) { echo 'You have entered an invalid character, or your sting is not 4-12 characters long.'; } That's just something that I found. I had the first snippet work on one page, but not on another. I did not take the time to figure out why, because this second snippet was the fix and I'm short on time. Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423739 Share on other sites More sharing options...
Dragen Posted December 26, 2007 Share Posted December 26, 2007 ah yeah.. another thing I missed out.. the brackets are neccessary. That's what I get for writing code at ridiculous times at night Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423744 Share on other sites More sharing options...
dsaba Posted December 27, 2007 Share Posted December 27, 2007 Most online resources are useless Not true. And still, isn't phpfreaks on online resource that you're using? Are we useless? Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-423934 Share on other sites More sharing options...
Dragen Posted December 27, 2007 Share Posted December 27, 2007 And still, isn't phpfreaks on online resource that you're using? Are we useless? no. we're just clumsy.. well, I am at any rate Link to comment https://forums.phpfreaks.com/topic/82637-solved-eregi-pattern/#findComment-424130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.