What is the easiest way to insert hyphens in javascript?
I have a phone number eg.1234567890
while displaying in the front end, I have to display it as 123-456-7890 using javascript.
what is the simplest and the quickest way to achieve this?
Thanks
try this...
Quickest way would be with some regex:
Where
n
is the numbern.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
Example: http://jsfiddle.net/jasongennaro/yXD7g/