1👍
✅
Since leading zero in a Number in javascript is ignored, you’ll need to work with strings
var firstnumber = '09151234567';
var secondnumber = '1075736332';
function modify(n) {
var re1 = /^(\d{4})(\d{3})(\d{4})$/;
var re2 = /^(\d{4})(\d{4})(\d\d)$/;
var m = n.match(n.length == 11 ? re1 : re2);
return m && m.slice(1).join(' ')
}
console.log(modify(firstnumber))
console.log(modify(secondnumber))
Source:stackexchange.com