Authored by xuqi

address detail err tip

... ... @@ -56,8 +56,15 @@ function queryString() {
return vars;
}
function getStrLength(str) {
var cArr = str.match(/[\u4e00-\u9fa5a]/ig);
return str.length + (cArr === null ? 0 : cArr.length);
}
module.exports = {
cookie: cookie, // 获取cookie
setCookie: setCookie, // 设置cookie
queryString: queryString // query参数解析
queryString: queryString, // query参数解析
getStrLength: getStrLength // 获取字符串长度(一个中文=2个字符)
};
... ...
... ... @@ -7,6 +7,7 @@
var $ = require('yoho-jquery'),
Hbs = require('yoho-handlebars'),
cascadingAddress = require('../../plugins/cascading-address'),
common = require('../common'),
popup = require('../../plugins/dialog');
var $receiver = $('#receiver');
... ... @@ -15,6 +16,8 @@ var Dialog = popup.Dialog,
Confirm = popup.Confirm,
Alert = popup.Alert;
var detailErr = '2-100字符。1个中文为2个字符';
var addressDialogTpl;
var addressTpl;
... ... @@ -67,10 +70,6 @@ function validateAddress($el) {
{
noEmpty: true,
err: '详细地址不能为空'
},
{
regx: /^[\u4e00-\u9fa5a-zA-Z\d#-()]+$/,
err: '只能包含数字、字母、汉字、#、-、()及其组合'
}
],
mobile: [
... ... @@ -121,6 +120,11 @@ function validateAddress($el) {
// 否则隐藏提示
$cur.siblings('.error-tips').hide();
}
if (key === 'detail' && common.getStrLength($cur.val()) > 100) {
pass = false;
$cur.siblings('.error-tips').find('em').text(detailErr).end().show();
}
}
}
... ... @@ -285,6 +289,17 @@ function initAddressContent($el, areaCode) {
if (areaCode) {
$el.address.setAddress(areaCode + ''); // need convert to string
}
// blur验证
$('.address-detail').on('blur', function() {
var $cur = $(this);
if (common.getStrLength($cur.val()) > 100) {
$cur.siblings('.error-tips').find('em').text(detailErr).end().show();
} else {
$cur.siblings('.error-tips').hide();
}
});
}
/**
... ...