ZhuXian Posted January 29, 2012 Share Posted January 29, 2012 Hello,Since I'm relatively new to PHP, I'm having troubles finding a way to check if the text user has input has only letters,and if it has only numbers or mixed it would print an error.Any help welcome. Link to comment Share on other sites More sharing options...
boen_robot Posted January 29, 2012 Share Posted January 29, 2012 There are numerous ways to do that, but the most popular one is with regular expressions.You can find more information about their syntax at the manual or at other sites.For doing the check you want, one way is to use the following: if (preg_match('/[:^alpha:]/', $input)) { echo 'Error: The input can only contain letters. No spaces, no digits, no punctuation - nothing other than letters.';} else { echo 'OK. The input contains only letters.';} Link to comment Share on other sites More sharing options...
ZhuXian Posted January 29, 2012 Author Share Posted January 29, 2012 Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.