如何检查字符是否是Javascript中的字母? [英] How to check if character is a letter in Javascript?

查看:161
本文介绍了如何检查字符是否是Javascript中的字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式提取Javascript字符串中的字符:

I am extracting a character in a Javascript string with:

var first = str.charAt(0);

,我想检查它是否是一封信。奇怪的是,它似乎并不像这样的功能存在于Javascript。至少我找不到。

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.

如何测试这个?

推荐答案

我相信此插件具有您所寻求的功能: http://xregexp.com/plugins/ ( github链接: https://github.com/slevithan/xregexp

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

有了它,你可以简单地匹配所有unicode字母与 \p {L}

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

阅读此源文件的标题,以查看其支持的类别: http:// xregexp .com / plugins / xregexp-unicode-categories.js

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

这篇关于如何检查字符是否是Javascript中的字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆