in my program php, I want the user doesn’t enter any caracters except the alphabets
like that : “dgdh”, “sgfdgdfg” but he doesn’t enter the numbers or anything else like “7657” or “gfd(-” or “fd54”
I tested this function but it doesn’t cover all cases :
preg_match("#[^0-9]#",$_POST['chaine'])
how can I achieve that, thank you in advance
The simplest can be
the
imodifier is for case-insensitive. The+is so that at least one alphabet is entered. You can change it to*if you want to allow empty string. The anchor^and$enforce that the whole string is nothing but the alphabets. (they represent the beginning of the string and the end of the string, respectively).If you want to allow whitespace, you can use:
Whitespace only at the beginning or end of string:
Any where:
Only the space character is allowed but not other whitespace: