dadamssg Posted March 13, 2009 Share Posted March 13, 2009 im tryin to write a pattern that must have 8 to 12 characters in it, and can only be letters or numbers, would i be close with something like this? ereg("^[A-Za-z]{8,9,10,11,12}$") i don't think i did the {} part right though i see an example of a patter, not really sure what it checks for but here it is ereg("^[A-Za-z' -]{1,50}$") im basing mine kind of off this Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/ Share on other sites More sharing options...
rhodesa Posted March 13, 2009 Share Posted March 13, 2009 not sure about ereg, but for preg it would be: if(preg_match('/^[a-z0-9]{8,12}$/i',$string)){ } Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784173 Share on other sites More sharing options...
dadamssg Posted March 13, 2009 Author Share Posted March 13, 2009 thank you thank you, what does the i mean? Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784197 Share on other sites More sharing options...
rhodesa Posted March 14, 2009 Share Posted March 14, 2009 case insensitive...so it will allow a-z and A-Z...you could also write it as: preg_match('/^[a-zA-Z0-9]{8,12}$/',$string) ...i just prefer the other way Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784230 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 sweet thanks Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784266 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 this isn't working...it will always say whatever the username is, isn't a valid one. if(!preg_match('/^[a-z0-9]{8,12}$/i',$_POST['username'])) { $messages="{$_POST['username']} is not a valid username."; } Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784306 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 i got it working...using this if(!eregi("^[A-Za-z' -]{8,14}$",$_POST['username'])) { $messages="Username must be only letters or numbers and have at least eight characters."; } Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784314 Share on other sites More sharing options...
.josh Posted March 14, 2009 Share Posted March 14, 2009 that eregi matches letters, a single quote, a space or a dash. no numbers. It also matches up to 14 chars. Also, you don't want to use eregi, because it will no longer be part of the core in php6, because the posix functions (eregxxx) suck compared to the pcre functions (pregxxx) If the preg_match one didn't work for you, try trimming the posted var first. Quote Link to comment https://forums.phpfreaks.com/topic/149318-solved-only-letters-and-numbers-min-8-max-12-characters/#findComment-784318 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.