Authored by 陈轩

短信登录 设置密码 优化完成

'use strict';
var config = {
rules: [
{method: 'required', param: []},
{method: 'lte', param: [20]},
{method: 'gte', param: [6]},
{method: 'charLimit', param: []}
],
msgs: {
required: '由字母、数字组合,不能包含特殊字符',
lte: '长度须在6-20个字符之间',
gte: '长度须在6-20个字符之间',
charLimit: '密码须为字母和数字组合'
}
};
var validators = {
required: function(val) {
return !!val.length;
},
gte: function(val, param) {
return val.length >= param;
},
lte: function(val, param) {
return val.length <= param;
},
charLimit: function(val) {
return /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(val);
}
};
function validate(val, callback) {
var rules = config.rules,
msgs = config.msgs,
i, ruleLen;
var name, param, pass = true;
// apple rule one by one;
for (i = 0, ruleLen = rules.length; i < ruleLen; i++) {
name = rules[i].method;
param = rules[i].param.concat();
param.unshift(val);
pass = validators[name].apply(this, param);
if (!pass) {
callback({ // eslint-disable-line
valid: pass,
msg: msgs[name]
});
break;
}
}
return pass;
}
// test
/* eslint-disable */
// validate('1234567', function(result) {console.log(result)})
// validate('12345', function(result) {console.log(result)});
// validate('a'.repeat(21), function(result) {console.log(result)});
// validate('1abcdefg', function(result) {console.log(result)});
/* eslint-enable */
module.exports = validate;
... ...
'use strict';
var tip, checkPoint;
var tip, checkPoint, validatePWD;
var $eyeBtn,
$pwd,
$nextBtn;
$nextBtn,
$pwdLint,
$pwdLintTxt;
var page;
require('js/common');
tip = require('plugin/tip');
checkPoint = require('./smslogin/check-point');
validatePWD = require('./password-check');
setTimeout(function() {
checkPoint('YB_SET_PASSWORD_L');
... ... @@ -24,6 +28,8 @@ page = {
$eyeBtn = $('#eye');
$pwd = $('#pwd');
$nextBtn = $('#btn-next');
$pwdLint = $('.js-password').find('.pwd-lint');
$pwdLintTxt = $pwdLint.find('.pwd-lint-txt');
},
bindEvent: function() {
var self = this;
... ... @@ -37,7 +43,14 @@ page = {
});
$pwd.on('input', function() {
var bool = Boolean($.trim(this.value));
var val = $.trim(this.value);
var bool = validatePWD(val, function(res) {
$pwdLint.css({visibility: res.valid});
if (!res.valid) {
$pwdLintTxt.text(res.msg);
}
});
$nextBtn
.toggleClass('disable', !bool)
... ...
... ... @@ -176,4 +176,13 @@ body.passport-body {
.row {
margin-bottom: 10PX;
}
.pwd-lint {
text-align: left;
color: #858585;
.icon-tip {
color: #4ecae8;
}
}
}
... ...