中文检查

用js脚本控制
我这里有现成的脚本
<script language=”javascript”>
function chkNum(obj,msg)
{

var str = obj.value;

var r = str.match(/^[1-9]d{0,}$/);

if(null==r)

{

alert(msg);

obj.select();

return false;

}

else

return true;
}
</script>
<SCRIPT>
function onlychinese()
{
if ((window.event.keyCode >=32) && (window.event.keyCode <= 126))
{
window.event.keyCode = 0 ;
}
}
</SCRIPT>
<input type=text onblur=”CheNum(this,’请输入数字’);”>
<input type=text onkeypress=”onlychinese();”>

<?php
$number = $_GET['number'];
$text = $_GET['text'];

// 仅允许数字
function chk_number($str) {
if(!preg_match("/^[0-9]{1,}$/",$str)) {
echo "Error!";
}else {
echo "OK";
}
}

// 检查中文
function chk_chinese($str) {
if(!preg_match("/^[x80-xff]{1,}$/",$str)) {
echo "Error!";
}else {
echo "OK";
}
}
echo "数字检查:";
chk_number($number);
echo "<br />中文检查:";
chk_chinese($text);
?>