JS 手机号/身份证/银行账号/邮箱/QQ/电话 掩码处理

本文介绍了多种敏感信息的掩码处理方法,包括手机号、身份证号、银行账号、邮箱、QQ号及电话号码的掩码算法,确保个人隐私安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

手机号掩码:

//手机号掩码
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值