UNPKG

igi_orion_cignacmb

Version:

Censors words out of text

136 lines (135 loc) 4.86 kB
/* * @Author: weicong.ling * @Date: 2020-05-06 10:07:19 * @Last Modified by: weicong.ling * @Last Modified time: 2020-05-11 09:59:56 */ /** * * @param {姓名} result */ var name = function (result) { var value = result.field.value; var error = { isCorrect: true, type: "modal", msg: "", code: "", isUse: true }; try { var sizeof = function (str, charset) { var total = 0, charCode, i, len; charset = charset ? charset.toLowerCase() : ''; if (charset === 'utf-16' || charset === 'utf16') { for (i = 0, len = str.length; i < len; i++) { charCode = str.charCodeAt(i); if (charCode <= 0xffff) { total += 2; } else { total += 4; } } } else { for (i = 0, len = str.length; i < len; i++) { charCode = str.charCodeAt(i); if (charCode <= 0x007f) { total += 1; } else if (charCode <= 0x07ff) { total += 2; } else if (charCode <= 0xffff) { total += 3; } else { total += 4; } } } return total; } var isChina = function (s) { var patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi; if (!patrn.exec(s)) { return false; } else { return true; } } var isEng = function (s) { if (s.search(/[a-zA-Z]+/) == -1) { return false; } else { return true; } } var isSpecial = function (s) { var pattern = new RegExp("[`~!@%#$^&*()=|{}':;',\\[\\]<>/?/\]\\.;:%……+¥()【】‘”“'●.。,、?1234567890-=_+~?!@#$%^&*)]"); if (pattern.test(s)) { return false; } else { return true; } } var isNumber = function (s) { var p = /[0-9]/; var b = p.test(s);//true,说明有数字 if (p.test(s)) { return false; } else { return true; } } var isHasBlank = function (s) { if (isChina(s)) { //只要中文才限制没有空格 if (s.indexOf(" ") == -1) { return true } else { return false } } } if (!value) { error.isCorrect = false; error.msg = '请输入姓名' } else { if (!isSpecial(value) || !isNumber(value)) { error.isCorrect = false; error.msg = '姓名中不允许出现特殊字符及阿拉伯数字' } else if (isChina(value)) { if (isEng(value)) { // error.isCorrect = false; // error.msg = '中文姓名和英文姓名只能录入其中一种' if (value.trim().length < 1 || value.length > 32) { error.isCorrect = false; error.msg = '姓名长度不符合要求,请您重新输入' } } else { if (result.item.idType && result.item.idType.value == 'P') { error.isCorrect = false; error.msg = '证件类型为护照,姓名必须是全英文' } else { if (value.length < 2 || value.length > 10) { error.isCorrect = false; error.msg = '中文姓名长度不符合要求,请您重新输入' } if (!isHasBlank(value)) { error.isCorrect = false; error.msg = '中文姓名中不允许出现空格' } } } } else { if (value.trim().length < 4 || value.length > 32) { error.isCorrect = false; error.msg = '英文姓名长度不符合要求,请您重新输入' } } } } catch (error) { console.error(error); } return error; }; module.exports = name;