Quickest way would be with some regex:
Where n
is the number
n.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
Example: http://jsfiddle.net/jasongennaro/yXD7g/
var n = "1234567899";
console.log(n.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3"));
More Related Contents:
- How to insert an element after another element in JavaScript without using a library?
- How to insert a row in an HTML table body in JavaScript
- Open window in JavaScript with HTML inserted
- Angular 2 Hover event
- JavaScript foreach loop on an associative array object
- Fire oninput event with jQuery
- Disable drop paste in HTML input fields? [duplicate]
- angular 2 access ng-content within component
- JavaScript asynchronous programming: promises vs generators
- Are 301 redirects possible using javascript or jQuery?
- Keeping history of hash/anchor changes in JavaScript
- Phantom JS synchronous AJAX request : NETWORK_ERR: XMLHttpRequest Exception 101
- Safely parsing a JSON string with unquoted keys
- Programmatically open “View Source” HTML Window in Browser with Javascript?
- Javascript: Get access to local variable or variable in closure by its name [duplicate]
- Is triggering event listeners using “.click()” asynchronous?
- ActiveX – Automation Server Can’t Create Object
- How to get HTTP status code of tags
- To detect if the user is closing the IE browser apart from onunload event, as it is triggerred when user does refresh etc [duplicate]
- How to to initialize keyboard event with given char/keycode in a Chrome extension?
- canvas- Cropping images in different shapes
- Javascript create variable from its name
- Image resize before upload
- JavaScript curly braces with no function or json
- Change map opacity outside circle of Google Maps JavaScript API v3
- Want to have an event handler for the browser’s back button with next.js
- Javascript Event Handler for Print
- ES6 arrow function and lexical scope inside a function [duplicate]
- How to call a function before leaving page with Javascript
- Get All Elements in an HTML document with a specific CSS Class