您的位置:首页 > Web前端 > JavaScript

javascript正则表达式

2016-07-25 13:31 309 查看
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checkType(){
var username = document.getElementById("username").value;
var flag = /^[\u4e00-\u9fa5]+$/  //将拷贝来的正则表达式放在。。。处     /^。。。+$/
if(!flag.test(username)){
alert("必须是汉字!");
}
}
</script>
</head>

<body>
<form action="#" method="post" name="form1" onsubmit="checkType()">
<label for="username">用户名</label>
<input type="text" name="username" id="username" />
<input type="submit" value="提交" />
</form>
</body>
</html>


写好的正则表达式很多,复制过来用就行了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: