@ararif/phone-format-js
v1.0.1
Published
Lightweight package to format phone number
Downloads
0
Readme
phone-format-js
Lightweight package to format phone number
Installation
Webpage
<script src="https://cdn.jsdelivr.net/gh/ararif724/phone-format-js/phone-format.js"></script>
Node JS
npm install @ararif/phone-format-js
Usage
formatPhoneNumber(number, [delimiter = " "])
Parameters
- number: [Required] Phone number
- delimiter: [Optional] character between 2 part of the number. Default is space
Returns
- Return formatted phone number
Example
Webpage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>phone-format-js</title>
<script src="https://cdn.jsdelivr.net/gh/ararif724/phone-format-js/phone-format.js"></script>
</head>
<body>
<input id="phone" type="phone" name="phone" />
<script>
document.addEventListener("DOMContentLoaded", function () {
var inputField = document.getElementById("phone");
inputField.addEventListener("input", function (e) {
e.target.value = formatPhoneNumber(e.target.value, "-");
});
});
</script>
</body>
</html>
Node JS
const phoneFormat = require("@ararif/phone-format-js");
const formattedNumber = phoneFormat("+8801912345678", "-");
console.log(formattedNumber);
License
This project is licensed under the MIT License - see the LICENSE file for details.