86Stang Posted November 28, 2009 Share Posted November 28, 2009 I've got this bit of code ready for accepting a phrase: if (!eregi ("", $_POST['phrase'])){ but I need it to accept ONLY alphabet characters. No numbers, no spaces, no under scores, no special characters. Anyone care to fill in the blank? Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/ Share on other sites More sharing options...
FaT3oYCG Posted November 28, 2009 Share Posted November 28, 2009 eregi is deprecated, preg_match("/^([a-z])*$/i", $_POST['phrase']) should work Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966859 Share on other sites More sharing options...
Virvo Posted November 28, 2009 Share Posted November 28, 2009 Craig is right, and in future releases of PHP (6+) ereg type functions will be removed altogether, so you should use the preg alternatives. Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966862 Share on other sites More sharing options...
FaT3oYCG Posted November 28, 2009 Share Posted November 28, 2009 sorry, i didnt make that clear, eregi is going to be deprecated as Virvo says so it is best practise to use the preg functions such as preg_match which is the same as eregi with some slightly different syntax and preg_replace which is the equivelant to eregi_replace, there is a tutorial on the php freaks site about the syntax here: http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966866 Share on other sites More sharing options...
86Stang Posted November 28, 2009 Author Share Posted November 28, 2009 Roger that! I'll replace it with preg_match. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966868 Share on other sites More sharing options...
salathe Posted November 28, 2009 Share Posted November 28, 2009 Since you're only looking to check if the value contains letters, you could also use the ctype_alpha function. Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966954 Share on other sites More sharing options...
Daniel0 Posted November 28, 2009 Share Posted November 28, 2009 Craig is right, and in future releases of PHP (6+) ereg type functions will be removed altogether, so you should use the preg alternatives. Actually, it'll just be moved to PECL as far as I know. Maybe things have changed though. Quote Link to comment https://forums.phpfreaks.com/topic/183203-accept-only-alpha-characters/#findComment-966958 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.