egturnkey Posted March 17, 2010 Share Posted March 17, 2010 Hello friends, If we have the following $manal = "hate1"; i wanna say if $manal has alphabetic letters ( not only digits ) then show something else then show anything if xxxxxxxx { echo 'something'; } else { echo 'anything'; } xxxxxx is the part i can't write, it want it means if $manal has letter and not digits hope you got what i mean, thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/ Share on other sites More sharing options...
JAY6390 Posted March 18, 2010 Share Posted March 18, 2010 if(!preg_match('/^\d+$/', $manal) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1027975 Share on other sites More sharing options...
Mchl Posted March 18, 2010 Share Posted March 18, 2010 ^\d will accept also non-letter characters. if(!preg_match('/[a-zA-Z]+$/', $manal) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1027981 Share on other sites More sharing options...
The Little Guy Posted March 19, 2010 Share Posted March 19, 2010 Is this what your looking for? <?php $strings = array('AbCd1zyZ9', 'foo!#$bar'); foreach ($strings as $testcase) { if (ctype_alnum($testcase)) { echo "The string $testcase consists of all letters or digits.\n"; } else { echo "The string $testcase does not consist of all letters or digits.\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1028425 Share on other sites More sharing options...
Mchl Posted March 19, 2010 Share Posted March 19, 2010 @TLG: If anything, it seems he wants ctype_alpha Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1028491 Share on other sites More sharing options...
JAY6390 Posted March 19, 2010 Share Posted March 19, 2010 The regex option seems a lot simpler to me lol Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1028495 Share on other sites More sharing options...
The Little Guy Posted March 19, 2010 Share Posted March 19, 2010 @TLG: If anything, it seems he wants ctype_alpha When I read his post, it just sounded like he wanted numbers and letters, maybe i was wrong... Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1028703 Share on other sites More sharing options...
Mchl Posted March 19, 2010 Share Posted March 19, 2010 Yeah... he writes basically two different thing in two places. Quote Link to comment https://forums.phpfreaks.com/topic/195559-if-it-has-alphabetic/#findComment-1028824 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.