angularjs:屏蔽SSN的前五个数字 [英] angularjs: mask the first five digits of SSN
本文介绍了angularjs:屏蔽SSN的前五个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用看起来像这样的过滤器屏蔽SSN的前5位数字 XXX-XX-1234
I'm trying to mask the first 5 digits of SSN using a filter which should look something like this
XXX-XX-1234
到目前为止,我想出了什么:
What I came up with so far:
// <td>{{SocialSecurityNumber | ssn}}
angular.module('ng').filter('ssn', function () {
return function (ssn) {
if (!ssn) {
return '';
}
var value = ssn.toString().trim().replace(/^\+/, '');
if (value.match(/[^0-9]/)) {
return ssn;
}
return (ssn.slice(0, 3).replaceWith('*') + '-' + ssn.slice(4, 5).replaceWith('*') + '-' + ssn.slice(4)).trim();
};
});
推荐答案
字符串在JavaScript中没有 .replaceWith
函数.不过,您可以使用 .replace
.
Strings have no .replaceWith
function in JavaScript. You can use .replace
, though.
我不确定 value.match(/[0-9]/)
应该做什么.看来您可以删除它.如果该值具有偶数位,则该值将返回 true
.也许您的意思是/[^ 0-9]/
I'm not sure what value.match(/[0-9]/)
is supposed to do either. It seems like you can just remove it. This will return true
if the value has even one digit, which it should anyway. Perhaps you mean /[^0-9]/
return "XXX-XX-" + ssn.slice(5);
这篇关于angularjs:屏蔽SSN的前五个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文