Skip to content

Instantly share code, notes, and snippets.

@wjfz
Created September 28, 2015 03:28
Show Gist options
  • Save wjfz/69cf427013218635c26a to your computer and use it in GitHub Desktop.
Save wjfz/69cf427013218635c26a to your computer and use it in GitHub Desktop.
检测语言
function isEnglish(s)
{
for(var i=0;i<s.length;i++)
{
if(s.charCodeAt(i)>126)
{
return false;
}
}
return true;
}
function isChinese(temp)
{
var re = /[^\u4e00-\u9fa5]/;
if(re.test(temp)) return false;
return true;
}
function isJapanese(temp)
{
var re = /[^\u0800-\u4e00]/;
if(re.test(temp)) return false;
return true;
}
function isKoera(chr) {
if(((chr > 0x3130 && chr < 0x318F) ||
(chr >= 0xAC00 && chr <= 0xD7A3)))
{
return true;
}
return false;
}
function isContainKoera(temp)
{
var cnt = 0;
for(var i=0;i < temp.length ; i++)
{
if(isKoera(temp.charAt(i)))
cnt++;
}
if (cnt > 0) return true;
return false;
}
function isContainChinese(temp)
{
var cnt = 0;
for(var i=0;i < temp.length ; i++)
{
if(isChinese(temp.charAt(i)))
cnt++;
}
if (cnt > 5) return true;
return false;
}
function isContainChinese2(temp)
{
var cnt = 0;
for(var i=0;i < temp.length ; i++)
{
if(isChinese(temp.charAt(i)))
cnt++;
}
if (cnt > 0 && temp.length<=3) return true;
return false;
}
function isContainJapanese(temp)
{
var cnt = 0;
for(var i=0;i < temp.length ; i++)
{
if(isJapanese(temp.charAt(i)))
cnt++;
}
if (cnt > 2) return true;
return false;
}
function ExtractEnglish(word)
{
var patt1 = new RegExp(/([a-zA-Z ]+)/);
var result = patt1.exec(word)[1];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment