I want a variable that allow letters and only
, not digits
.
And that variable can be at any position in the string.
Look at this,
$pattern = '~user/(:var)~';
$pattern = str_replace('(:var)', '([a-zA-Z])', $pattern);
// Note, the variable contain both numbers and letters
$test = 'user/dave123';
$r = preg_match($pattern, $test);
var_dump($r); //1 Success (I don't want this)
All I want is,
If a variable contain letters only, then preg_match()
should return 1
,
but if that one contains at least one digit, then preg_match()
should immediately return 0,
What regex
should be defined instead of ([a-zA-Z])
and why ([a-zA-Z])
matches both numbers and letters!?