jquery中如何让判断文本框输入的是中文?

2025-04-11 11:10:44
推荐回答(1个)
回答1:

判断文本框输入的内容是否为汉字,利用文本框的键盘事件KeyPressEventArgs;

public static bool IsChinese(KeyPressEventArgs e,DevExpress.XtraEditors.TextEdit text)  
     {  
         if ((e.KeyChar >= (char)0x4e00) && (e.KeyChar <= (char)0x9fa5) || (byte)(e.KeyChar) == 8)  
         {  
             e.Handled = false;  
             return true;  
         }  
         else  
         {  
             e.Handled = true;  
             return false;  
         }  
     }

jquery判断文本框输入的必须是中文


 $(function () {
 $("input[type=button]").click(function () {
 var myReg = /^[一-龥]+$/;
 if (myReg.test($("input[type=text]").val())) {
 alert("输入正确");
 } else {
 alert("输入错误");
 }
 })
 });