常见正则表达式:
[0-9] 0到9任意1个数字
[a-z] a到z任意一个字母
[A-Z] A到Z任意一个字母
[0-9]{1} 0到9任意1个数字
[0-9]{2} 0到9任意2个数字
[0-9]{2,} 0到92+个数字(次数 >= 2)
[0-9]{2,3} 0到9数字出现个数为2到3次。
[0-9]+ 出现1到N次
[0-9]* 出现0到N次
[0-9]? 出现1或0次
^ 字符串开始
$ 字符串结尾
<%@page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<link href="jquery/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function(){
$("#code").blur(function(){
var code = $.trim(this.value);
if(code == ""){
$("#codeErrorMsg").text("编码不能为空!");
} else {
var regExp = /^[0-9a-zA-Z]+$/;
var ok = regExp.test(code);
if(ok){
$.ajax({
type : "get",
url : "settings/dictionary/type/checkCodeUnique.do",
async : false,
cache : false,
data : {
"code" : code
},
success : function(json){
if(json.success){
$("#codeErrorMsg").text("");
}else{
$("#codeErrorMsg").text("编码已存在!");
}
}
});
}else{
$("#codeErrorMsg").text("编码只能由数字和字母组成!");
}
}
});
$("#code").focus(function(){
if($("#codeErrorMsg").text() != ""){
$(this).val("");
}
$("#codeErrorMsg").text("");
});
$("#saveBtn").click(function(){
$("#code").blur();
if($("#codeErrorMsg").text() == ""){
$("#dicTypeForm").submit();
}
});
});
</script>
</head>
<body>
<div style="position: relative; left: 30px;">
<h3>新增字典类型</h3>
<div style="position: relative; top: -40px; left: 70%;">
<button type="button" class="btn btn-primary" id="saveBtn">保存</button>
<button type="button" class="btn btn-default" onclick="window.history.back();">取消</button>
</div>
<hr style="position: relative; top: -40px;">
</div>
<form id="dicTypeForm" action="settings/dictionary/type/save.do" method="post" class="form-horizontal" role="form">
<div class="form-group">
<label for="create-code" class="col-sm-2 control-label">编码<span style="font-size: 15px; color: red;">*</span></label>
<div class="col-sm-10" style="width: 300px;">
<input type="text" class="form-control" id="code" name="code" style="width: 200%;" placeholder="编码作为主键,不能是中文">
<span id="codeErrorMsg" style="color: red;font-size: 12px;"></span>
</div>
</div>
<div class="form-group">
<label for="create-name" class="col-sm-2 control-label">名称</label>
<div class="col-sm-10" style="width: 300px;">
<input type="text" class="form-control" id="name" name="name" style="width: 200%;">
</div>
</div>
<div class="form-group">
<label for="create-describe" class="col-sm-2 control-label">描述</label>
<div class="col-sm-10" style="width: 300px;">
<textarea class="form-control" rows="3" id="description" name="description" style="width: 200%;"></textarea>
</div>
</div>
</form>
<div style="height: 200px;"></div>
</body>
</html>