laserlight;10925108 wrote:If you only want to allow letters, use [man]ctype_alpha/man. That said, the problem with your regex pattern is that it asserts the start of the input. If you change it to /[a-zA-Z]/ then it will work.
By the way, use single quotes for regex patterns.
Granted, depending on the locale, ctype_alpha might not be sufficient 'as is'. If the goal is to in fact only allow a-zA-Z, it might be necessary to either:
a) explicitly state the letter range (as you have shown with your pattern),
or
b) declare setlocale(LC_CTYPE, 'C'); prior to using ctype_alpha (or any other ctype functions / regex patterns with character classes like \d, \w, etc) to ensure the locale in question doesn't botch things up with unexpected results (in this case, think along the lines of accented characters).
<--- hates locale issues :mad: