Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed Mar 3, 2024
1 parent e1d7d9b commit 0a906ca
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
/*this is basic form validation using for validation person's basic information author:Clara Guo data:2017/07/20*/
$(document).ready(function(){
$.validator.setDefaults({
submitHandler: function(form) {
form.submit();
submitHandler: function(form) {
form.submit();
}
});
//手机号码验证身份证正则合并:(^\d{15}$)|(^\d{17}([0-9]|X)$)
jQuery.validator.addMethod("isPhone",function(value,element){
});
// 非法字符验证
jQuery.validator.addMethod("specialSign",function(value,element) {
var char = /^[^<>"'|\\]+$/;
return this.optional(element) || (char.test(value));
},"不能包含非法字符:< > \" ' \\\ |");
// 手机号码验证身份证正则合并:(^\d{15}$)|(^\d{17}([0-9]|X)$)
jQuery.validator.addMethod("isPhone",function(value,element) {
var length = value.length;
var phone=/^1[3-9]\d{9}$/;
var phone = /^1[3-9]\d{9}$/;
return this.optional(element)||(length == 11 && phone.test(value));
},"请填写正确的11位手机号");
//电话号码验证
jQuery.validator.addMethod("isTel",function(value,element){
// 电话号码验证
jQuery.validator.addMethod("isTel",function(value,element) {
var tel = /^(0\d{2,3}-)?\d{7,8}$/g;//区号3,4位,号码7,8位
return this.optional(element) || (tel.test(value));
},"请填写正确的座机号码");
//姓名校验
jQuery.validator.addMethod("isName",function(value,element){
var name=/^[\u4e00-\u9fa5]{2,6}$/;
// 姓名校验
jQuery.validator.addMethod("isName",function(value,element) {
var name = /^[\u4e00-\u9fa5]{2,6}$/;
return this.optional(element) || (name.test(value));
},"姓名只能用汉字,长度2-4位");
//校验用户名
jQuery.validator.addMethod("isUserName",function(value,element){
var userName=/^[a-zA-Z0-9]{2,13}$/;
// 校验用户名
jQuery.validator.addMethod("isUserName",function(value,element) {
var userName = /^[a-zA-Z0-9]{2,13}$/;
return this.optional(element) || (userName).test(value);
},'请输入数字或者字母,不包含特殊字符');

//校验身份证
jQuery.validator.addMethod("isIdentity",function(value,element){
var id= /^(\d{15}$|^\d{18}$|^\d{17}(\d|X))$/;
// 校验身份证
jQuery.validator.addMethod("isIdentity",function(value,element) {
var id = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X))$/;
return this.optional(element) || (id.test(value));
},"请输入正确的15或18位身份证号,末尾若为X请大写");
//校验二代身份证
jQuery.validator.addMethod("isIdentity18",function(value,element){
var id= /^(^\d{17}(\d|X))$/;
// 校验二代身份证
jQuery.validator.addMethod("isIdentity18",function(value,element) {
var id = /^(^\d{17}(\d|X))$/;
return this.optional(element) || (id.test(value));
},"请输入正确的18位身份证号,末尾若为X请大写");
//校验出生日期
jQuery.validator.addMethod("isBirth",function(value,element){
// 校验出生日期
jQuery.validator.addMethod("isBirth",function(value,element) {
var birth = /^(19|20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/;
return this.optional(element) || (birth).test(value);
},"出生日期格式示例2000-01-01");
//校验IP地址
jQuery.validator.addMethod("isIp",function(value,element){
// 校验IP地址
jQuery.validator.addMethod("isIp",function(value,element) {
var ip = /^(?:(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:1[0-9][0-9]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:2[0-4][0-9])|(?:25[0-5])|(?:1[0-9][0-9])|(?:[1-9][0-9])|(?:[0-9]))$/;
return this.optional(element) || (ip).test(value);
},"IP地址格式示例127.0.0.1");
Expand All @@ -53,7 +57,7 @@ $(document).ready(function(){
jQuery.validator.addMethod("gt", function(value, element, param) {
return value > param;
}, $.validator.format("输入值必须大于{0}"));
//校验新旧密码是否相同
// 校验新旧密码是否相同
jQuery.validator.addMethod("isdiff",function(){
var p1=$("#pwdOld").val();
var p2=$("#pwdNew").val();
Expand All @@ -63,7 +67,7 @@ $(document).ready(function(){
return true;
}
});
//校验新密码和确认密码是否相同
// 校验新密码和确认密码是否相同
jQuery.validator.addMethod("issame",function(){
var p3=$("#confirm_password").val();
var p4=$("#pwdNew").val();
Expand All @@ -73,7 +77,7 @@ $(document).ready(function(){
return false;
}
});
//校验基础信息表单
// 校验基础信息表单
$("#basicInfoForm").validate({
errorElement:'span',
errorClass:'help-block error-mes',
Expand Down Expand Up @@ -133,11 +137,11 @@ $(document).ready(function(){
}
});

//校验修改密码表单
// 校验修改密码表单
$("#modifyPwd").validate({
onfocusout: function(element) { $(element).valid()},
debug:false, //表示校验通过后是否直接提交表单
onkeyup:false, //表示按键松开时候监听验证
debug:false, // 表示校验通过后是否直接提交表单
onkeyup:false, // 表示按键松开时候监听验证
rules:{
pwdOld:{
required:true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ $(function() {
});
});

$.validator.setDefaults({
submitHandler: function() {
login();
}
});

function login() {
var username = $.common.trim($("input[name='username']").val());
var password = $.common.trim($("input[name='password']").val());
Expand Down Expand Up @@ -66,6 +60,9 @@ function validateRule() {
password: {
required: icon + "请输入您的密码",
}
},
submitHandler: function(form) {
login();
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ $(function() {
});
});

$.validator.setDefaults({
submitHandler: function() {
register();
}
});

function register() {
var username = $.common.trim($("input[name='username']").val());
var password = $.common.trim($("input[name='password']").val());
Expand Down Expand Up @@ -63,7 +57,8 @@ function validateRule() {
},
password: {
required: true,
minlength: 5
minlength: 5,
specialSign: true
},
confirmPassword: {
required: true,
Expand All @@ -83,6 +78,9 @@ function validateRule() {
required: icon + "请再次输入您的密码",
equalTo: icon + "两次密码输入不一致"
}
},
submitHandler: function(form) {
register();
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ <h4 class="no-margins">注册:</h4>
<!-- 全局js -->
<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../static/ajax/libs/validate/jquery.validate.min.js" th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
<script src="../static/ajax/libs/validate/jquery.validate.extend.js" th:src="@{/ajax/libs/validate/jquery.validate.extend.js}"></script>
<script src="../static/ajax/libs/layer/layer.min.js" th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.7.7}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ <h4 class="form-header h4">其他信息</h4>
},
password:{
minlength: 5,
maxlength: 20
maxlength: 20,
specialSign: true
},
email:{
email:true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ <h5>基本资料</h5>
newPassword: {
required: true,
minlength: 6,
maxlength: 20
maxlength: 20,
specialSign: true
},
confirmPassword: {
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
newPassword: {
required: true,
minlength: 5,
maxlength: 20
maxlength: 20,
specialSign: true
},
confirmPassword: {
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
<label class="col-sm-3 control-label">输入密码:</label>
<div class="col-sm-8">
<div class="input-group">
<input class="form-control" type="password" name="password" id="password" placeholder="请输入重置密码" th:value="${@config.getKey('sys.user.initPassword')}">
<span class="input-group-addon" title="重置密码,鼠标按下显示密码" onmousedown="$('#password').attr('type','text')" onmouseup="$('#password').attr('type','password')"><i class="fa fa-key"></i></span>
</div>
<input class="form-control" type="password" name="password" id="password" placeholder="请输入重置密码" th:value="${@config.getKey('sys.user.initPassword')}">
<span class="input-group-addon" title="重置密码,鼠标按下显示密码"
onmousedown="$('#password').attr('type','text')"
onmouseup="$('#password').attr('type','password')"><i class="fa fa-key"></i></span>
</div>
</div>
</div>
</form>
Expand All @@ -29,9 +31,10 @@
$("#form-user-resetPwd").validate({
rules:{
password:{
required:true,
required: true,
minlength: 5,
maxlength: 20
maxlength: 20,
specialSign: true
},
},
focusCleanup: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ public class Constants
*/
public static final String LOOKUP_LDAPS = "ldaps:";

/**
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
*/
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };

/**
* 定时任务违规的字符
*/
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };

/**
* UUID generator
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ public boolean isValid(String value, ConstraintValidatorContext constraintValida

public static boolean containsHtml(String value)
{
StringBuilder sHtml = new StringBuilder();
Pattern pattern = Pattern.compile(HTML_PATTERN);
Matcher matcher = pattern.matcher(value);
return matcher.matches();
while (matcher.find())
{
sHtml.append(matcher.group());
}
return pattern.matcher(sHtml).matches();
}
}
Loading

0 comments on commit 0a906ca

Please sign in to comment.