jQuery验证车牌号(含新能源车牌)
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title>test</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-md-12 col-sm-12col-xs-12">
<div class="form-group">
<label class="col-md-3 col-sm-3col-xs-3 control-label">车牌号
</label>
<div class="col-md-5 col-sm-5col-xs-5">
<input type="text" class="form-control " placeholder="请输入车牌号" id="carNumb" name="carNumb">
</div>
</div>
</div>
<button type="button" class="btn btn-primary" style="margin-left:28px;" >submit</button>
<script type="text/javascript">
function submit() {
/* 车牌号码验证 */
var $car_num = $("#carNumb").val();
var reg01 =
/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领](({5})|((){4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{4}))$/;
if (reg01.test($car_num)) {
alert("车牌号正确");
} else {
alert("请填写正确的车牌号")
return;
}
}
</script>
</body>
</html>
以京BA602K为例
验证正确
文档来源:51CTO技术博客https://blog.51cto.com/u_15315508/3208099
页:
[1]