简体   繁体   English

Live Update数据掩码属性可正确屏蔽数据

[英]Live Update data-mask attribute for correct data masking

I am using boot-strap data masking on my form. 我在表单上使用引导数据屏蔽。 I have a select drop down where the user can select different Card Types. 我有一个选择下拉菜单,用户可以在其中选择不同的卡类型。 For example American Express, Discover, Visa.... 例如,美国运通卡,发现卡,维萨卡...。

When the user selects American Express then I wan the text input for credit card number to mask the input as "5555-555555-55555". 当用户选择美国运通卡时,我希望输入信用卡号的文本来将输入掩盖为“ 5555-555555-55555”。 When any other Credit Card type then I want the inout mask should be "5555-5555-5555-5555". 当使用其他任何类型的信用卡时,我希望输入掩码应为“ 5555-5555-5555-5555”。 16 digits for credit card other than American Express and 15 digits for American Express along with hyphens at correct place. 信用卡(美国运通卡除外)的16位数字和美国运通卡的15位数字以及正确位置的连字符。

I have this in my code till now 到目前为止,我的代码中都包含这个

$(document).on("change", "#creditcardtype", function(){
    if($(this).val() == "American Express"){
        $("#Cnumber").attr("data-mask","9999-999999-99999");
    }else{
        $("#Cnumber").attr("data-mask", "9999-9999-9999-9999");
    }
});

This code updates the data mask for the first time and does not update the next time if the card type is changed. 如果卡类型更改,则此代码将首次更新数据掩码,而下次不会更新。 Any help please ?? 任何帮助请??

Instead of changing attributes, re-initialize masking on the selected field. 不用更改属性,而是在所选字段上重新初始化掩码。 For Example 例如

$(element).mask('099.099.099.099'); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM