I'm trying to determine the regular expression to verify that a string has at least one alphabetic character.
Any help would be appreciated.
Thanks.
I'm trying to determine the regular expression to verify that a string has at least one alphabetic character.
Any help would be appreciated.
Thanks.
Try this
"^.*[a-zA-Z].*$"
This will work with most regex engines. However it is limited to ASCII alphabetical characters. For international characters we'd need to know the regex engine involved.
The POSIX standard match for alphabetic characters is:
[[:alpha:]]
The .net
equivalent is
[\p{L}]
where this is an MS shortcut for Unicode's 5 different "letter" character classes, which are also supported by Java:
[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}]
Note that this should also match any characters that are alphabetic, not just the usual Roman alphabet's "[a-zA-Z]
" set, and therefore also matches accented characters, etc.
[a-zA-Z]
or even [a-z]
if you pass the case-insensitive option to your regular expression engine.
Don't forget that the definition of 'alphabetic character' is not the same all over the world. For instance, in Norway, the correct regex is [a-zA-ZæøåÆØÅ]
.