I want to mask my javascript variable value.Basically i am getting phone number fields value in variable and after getting it i want to mask it in some other format.
There is a javascript library that provides a solution for this problem:
https://github.com/the-darc/string-mask
And you don't need to create a new regular expression every time you change your mask(Format).
You can use it just like that:
var formatter = new StringMask("(000) 000-0000", { reverse: true });
var result = formatter.apply('123456789'); // (012) 345-6789
or
var formatter = new StringMask('#.##0,00', { reverse: true });
var result = formatter.apply('123456789'); // 1.234.567,89