var x2 = this.phone.replace(/\D/g,'').replace(/^7(\d{10})$/,'$1');
var x = x2.match( /^(\d{0,3})(\d{0,3})(\d{0,4})$/);
this.phone =
(x2.length==10?'7 ':'')
+ ( !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3]? '-' + x[3] : '') );
return this.phone;}).call({ phone:phone });
}
console.dir(
[
'79000000000','9000000000','7 (900) 000-0000','(900) 000-0000',
'1234567890', '123456789', '12345678', '1234567', '123456', '12345', '1234', '123', '12', '1', ''
]
.map(test)
);->
0: "7 (900) 000-0000"
1: "7 (900) 000-0000"
2: "7 (900) 000-0000"
3: "7 (900) 000-0000"
4: "7 (123) 456-7890"
5: "(123) 456-789"
6: "(123) 456-78"
7: "(123) 456-7"
8: "(123) 456"
9: "(123) 45"
10: "(123) 4"
11: "123"
12: "12"
13: "1"
14: ""
не похоже на общепринятый формат телефонного номера
Обсуждают сегодня