日期:2014-05-16 浏览次数:20333 次
function NameLeng() { var re = /^[\u4e00-\u9fa5]+$/; var res = /^[a-zA-Z0-9_]{1,}$/; var username = document.getElementById("userName"); if (re.test(document.getElementById('userName').value)) { alert("不能输入中文"); return false; }if (!res.test(document.getElementById('userName').value)) { alert("非法输入用户名"); return false; } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <input type='text' id='userName' onblur='NameLeng()' /> <script> function NameLeng() { var res = /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/; if (!res.test(document.getElementById('userName').value)) { alert("非法输入用户名"); document.getElementById('userName').value = ''; return false; } } </script> </body> </html>