Lamez Posted October 13, 2010 Share Posted October 13, 2010 Is there a string function that checks a string for numbers and symbols, or in other words, check to make sure it only contains letters, or do I have to write one? Quote Link to comment https://forums.phpfreaks.com/topic/215798-is-there-a-function/ Share on other sites More sharing options...
litebearer Posted October 13, 2010 Share Posted October 13, 2010 http://www.totallyphp.co.uk/code/check_that_characters_in_a_variable_are_alpha_numeric_using_ereg.htm Quote Link to comment https://forums.phpfreaks.com/topic/215798-is-there-a-function/#findComment-1121859 Share on other sites More sharing options...
Lamez Posted October 13, 2010 Author Share Posted October 13, 2010 Oh cool, so I would need to modify it like so: if (ereg('[^A-Za-z]', $text)) { echo "Contains only letters"; } Right? Quote Link to comment https://forums.phpfreaks.com/topic/215798-is-there-a-function/#findComment-1121861 Share on other sites More sharing options...
rwwd Posted October 13, 2010 Share Posted October 13, 2010 ctype_alpha() See the manual as the ctype_ has many different applications, but there is a preg_match angle that you can do too which is something like this:- !preg_match("/^\d+$/im", $input);<-- Inverting it so it does what you want, doesn't allow digits.. At least I think I have that right.. if (ereg('[^A-Za-z]', $text)) Ereg functions have been deprecated a while now in preference to preg_ functions... The manual tells you all you need to know.. Rw Quote Link to comment https://forums.phpfreaks.com/topic/215798-is-there-a-function/#findComment-1121864 Share on other sites More sharing options...
Lamez Posted October 13, 2010 Author Share Posted October 13, 2010 I used ctype_alpha. I knew there was one, but I forgot it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/215798-is-there-a-function/#findComment-1121866 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.