版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/My_ben/article/details/83538020
手机号掩码:
//手机号掩码
function mobilePhoneMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
if (input.length > 6) {
output = input.substr(0, 3) + "*****" + input.substr(input.length - 3);
}
else if (input.length > 3) {
output = input.substr(0, 3) + "*****";
}
else if (input.length > 0) {
output = input.substr(0, 1) + "*****";
}
return output;
}
可如下调用:
{
field: "MobilePhone", title: "手机", width: 100, formatter: mobilePhoneMask, align: "center"
}
效果如下:
身份证号掩码:
//身份证号掩码:
function idCardMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
if (input.length > 4) {
output = input.substr(0, 2) + "**************" + input.substr(input.length - 2);
}
else if (input.length >= 2) {
output = input.substr(0, 2) + "**************";
}
else {
output = input + "**************";
}
return output;
}
效果如下:
银行账号掩码:
//银行账号掩码
function bankAccountMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
if (input.length > 8) {
output = input.substr(0, 4) + "****" + input.substr(input.length - 4);
}
else if (input.length > 4) {
output = input.substr(0, 4) + "****";
}
else if (input.length > 0) {
output = input + "****";
}
return output;
}
效果如下:
邮箱掩码:
//邮箱掩码
function emailMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
var emailParts = input.split("@");
if (emailParts.length > 1) {
if (emailParts[0].length > 3)
output = emailParts[0].substr(0, 2) + "***" + emailParts[0].substr(emailParts[0].length - 1);
else if (emailParts[0].length > 0)
output = emailParts[0].substr(0, 1) + "***";
output += "@" + emailParts[1];
}
return output;
}
QQ掩码:
//qq掩码
function qqMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
if (input.length > 4) {
output = input.substr(0, 2) + "***" + input.substr(input.length - 2);
}
else if (input.length > 0) {
output = input.substr(0, 1) + "***";
}
return output;
}
电话掩码:
//电话掩码
function telMask(input) {
var output = input;
if (input == null || input == "")
return output;
output = input = $.trim(input);
var telParts = input.split("-");
if (telParts.length > 1) {
if (telParts[1].length > 4) {
telParts[1] = telParts[1].substr(0, 2) + "***" + telParts[1].substr(telParts[1].length - 2);
}
else if (telParts[1].length > 0) {
telParts[1] = telParts[1].substr(0, 1) + "***";
}
}
if (telParts.length > 2) {
if (telParts[2].length > 0) {
telParts[2] = telParts[2].substr(0, 1) + "**";
}
}
output = telParts.join("-");
return output;
}