Asp.net, C # version:
/// <Summary>
/// Check whether all Chinese characters exist
/// </Summary>
/// <Param name = "inputtext"> string to be checked </param>
/// <Returns> </returns>
Public bool ishaschzn (string inputtext)
{
System. Text. regularexpressions. RegEx regxs = new system. Text. regularexpressions. RegEx ("^ [\ u4e00-\ u9fa5] | [\ ufe30-\ uffa0] $ ");
Return regxs. ismatch (inputtext );
}
/// <Summary>
/// Check for Chinese Characters
/// </Summary>
/// <Param name = "inputtext"> string to be checked </param>
/// <Returns> </returns>
Public bool ishaschzn_c (string Str)
{
Byte [] strascii = system. Text. asciiencoding. ASCII. getbytes (STR );
Int tmpnum = 0;
For (INT I = 0; I <Str. length; I ++)
{
// Chinese check
If (INT) strascii [I]> = 63 & (INT) strascii [I] <91)
{
Tmpnum + = 2;
}
}
If (tmpnum> 2)
{
Return true;
}
Else
{
Return false;
}
}
JS version:
<SCRIPT type = "text/JavaScript">
Function ischina (s) // determines whether the character is a Chinese character
{
VaR patrn =/[\ u4e00-\ u9fa5] | [\ ufe30-\ uffa0]/GI;
If (! Patrn.exe C (s ))
{
Return false;
} Else {
Return true;
}
}
Alert (ischina ('www '));
Alert (ischina ('China '));
</SCRIPT>