在HTML5中,可以通过pattern属性添加正则表达式,从而进行表单验证(只有在点击提交的时候进行验证):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
</style>
</head>
<body>
<form action="#">
<input type="text" title="input your name" pattern="[A-Z]{3}-[0-9]{3}">
<input type="submit">
</form>
</body>
</html>