Jump to content

Check if text user has input contains only letters.


Recommended Posts

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.';}

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...