JVerstry JVerstry - 2 months ago 9
Javascript Question

How to check if character is a letter in Javascript?

I am extracting a character in a Javascript string with:

var first = str.charAt(0);

and I would like to check whether it is a letter. Strangely, it does not seem like such functionality exists in Javascript. At least I cannot find it.

How can I test this?


I believe this plugin has the capabilities you seek: http://xregexp.com/plugins/ (github link: https://github.com/slevithan/xregexp)

With it you can simply match all unicode letters with \p{L}.

Read the header of this source file to see which categories it supports: http://xregexp.com/plugins/xregexp-unicode-categories.js