1. 正则表达以及失去焦点验证的JS书写
<script>
function leave(a) {
var reg = /^[ \u4e00-\u9fa5a-zA-Z0-9_-]{5,16}$/;//[ title: [/^[a-zA-Z0-9_-]{5,16}$/, '用户名是5-16不含空的字母'],
if (reg.test(a.value) != true) {
var username = a.value;
if (username.length == 0 || username == null || username == '') {
layer.msg('用户名不能为空', {icon: 5});
a.style.border = "1px solid red";
} else {
if (!reg.test(username)) {
layer.msg('格式不对,用户名是5-15不含空的字符', {icon: 5});
a.style.border = "1px solid red";
}
}
} else {
a.style.border = "";
}
}
// 2. 验证密码,失去焦点时触发
function leave1(a) {
var reg = /^[a-zA-Z0-9_-]{6,20}$/;//正则表达式
if (reg.test(a.value) != true) {
var username = a.value;
if (username.length == 0 || username == null || username == '') {
layer.msg('密码不能为空', {icon: 5});
a.style.border = "1px solid red";
} else {
if (!reg.test(username)) {
layer.msg('密码格式不对,密码是6-20个字符,由数字和字母构成', {icon: 5});
a.style.border = "1px solid red";
}
}
} else {
a.style.border = "";
}
}
function leave2(a) {
var reg = /^[\u4e00-\u9fa5]{2,5}$/;//正则表达式
if (reg.test(a.value) != true) {
var username = a.value;
if (username.length == 0 || username == null || username == '') {
// 提示弹框 以及图标
layer.msg('真实姓名不能为空', {icon: 5});
a.style.border = "1px solid red";
} else {
if (!reg.test(username)) {
layer.msg('格式不对,真实姓名为2-5个汉字', {icon: 5});
a.style.border = "1px solid red";
}
}
} else {
a.style.border = "";
}
}
// phone: [/^1\d{10}$/, "请输入正确的手机号"],
function leave6(a) {
var reg = /^1\d{10}$/;//正则表达式
if (reg.test(a.value) != true) {
var username = a.value;
if (username.length == 0 || username == null || username == '') {
layer.msg('手机号不能为空', {icon: 5});
a.style.border = "1px solid red";
} else {
if (!reg.test(username)) {
layer.msg('格式不对,请输入正确的手机号', {icon: 5});
a.style.border = "1px solid red";
}
}
} else {
a.style.border = "";
}
}
</script>
2. 展示页面 不允许修改
在文本标签中中添加 disable展示 则不允许进行文本框的输入