如何在JavaScript中检查字符 [英] How to check a character in javascript
本文介绍了如何在JavaScript中检查字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在javascript中检查字符是小写字母还是大写字母
How can i check a character whether it is small letter or captial letter in javascript
推荐答案
一种方法是执行以下操作:
One way is to do this:
string a = "a";
if (a == a.toUpperCase())
{
// it's uppercase
}
另一种方法是使用正则表达式:
Another way is with regular expressions:
var check = /[:upper:]/;
alert(check.test("R")); // returns true
alert(check.test("r")); // returns false
一种方法通过使用toLowerCase()和toUpperCase()函数可以做到这一点.您可以使用这两个函数,将每个结果分配给一个单独的变量,然后与原始字符进行比较.如果原始字符等于toLowerCase()的结果,则其为小写字母,否则为大写字母.希望你能明白.
One way of doing it is by using toLowerCase() and toUpperCase() functions. You can use the two functions, assign each result to a separate variable, and then compare to the original character. If original character is equal to the result of toLowerCase(), then its a lower case, else, upper case. Hope you get the idea.
这篇关于如何在JavaScript中检查字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文