正则表达式
<%--
Created by IntelliJ IDEA.
User: dell
Date: 2020/10/10
Time: 15:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<%-- 引入JQuery库--%>
<script type="text/javascript" src="Jquery/jquery-1.7.2(1).js"></script>
<script type="text/javascript">
$(function () {
$("#sub").click(function () {
var username = $("#usn").val()
var userReg = /a/;
var flag = userReg.test(username);
if (!flag){
alert("请输入包含a的用户名")
return false
}
})
})
</script>
<title>正则表达式</title>
</head>
<body>
<form action="index.jsp" method="post">
用户名:<input type="text" name="username" id="usn"><br>
<input type="submit" id="sub">
</form>
</body>
</html>