I am applying phone number masking on a phone number. I want to make sure that there is no +1 in the beginning and if there is remove it. What would be the best way to do that?
self.phoneNumberMasking = function (data) {
if (data != "" && data != null) {
var x = data.replace(/\D/g, '').match(/(\d{3})(\d{3})(\d{4})/);
data = '+1(' + x[1] + ')' + x[2] + '-' + x[3];
return data;
}
return data;
}
Since I am not removing or replacing +1 in the above code, it is adding another 1 when I try to apply the mask on a number that already has +1 in it.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/yKeT96C
Comments
Post a Comment