手机号掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//手机号掩码
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;
}

身份证号掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//身份证号掩码:
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;
}

银行账号掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//银行账号掩码
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;
}

邮箱掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//邮箱掩码
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掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//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;
}

电话掩码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//电话掩码
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;
}