Created
July 31, 2014 15:37
-
-
Save jikeytang/484433779f3d7f88e782 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140801-题目1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
请问JS怎么判断中文,数字,字母? | |
PS: | |
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。 | |
```javascript | |
// you code | |
``` | |
2. 粘贴代码时请使用shift+tab,缩进前面的空白。 |
muzilei
commented
Aug 2, 2014
楼上大湿们 回答已经很全。 列出最近正好用到的
// 是否包含中文
var t ="中文0f"
return t.length ===t.replace(/[\u4e00-\u9fa5]/g,'**').length
function testS(str){
if(typeof str=="number"){
return "数字";
}
if(str.charCodeAt(0)>256){
return "中文字符串";
}
if(str.charCodeAt(0)<=256){
return "字母";
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment