[\u4e00-\u9fa5]html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>title</title> </head> <body> 請輸入您的名字:<input type="text" value="" id="userName" />*<br /> <script> //是中文名字,則綠色,不然紅色 document.getElementById("userName").onblur = function () { var reg = /^[\u4e00-\u9fa5]{2,6}$/; if (reg.test(this.value)) { this.style.backgroundColor = "green"; } else { this.style.backgroundColor = "pink"; } }; </script> </body> </html>