VN-PHONE-VALIDATOR
vn-phone-validator là một package hỗ trợ xử lý số điện thoại đầu số ở Việt Nam. Nó đơn giản, mạnh mẽ & dễ sử dụng.
Installation
$ npm i vn-phone-validator
API
const phoneValidate = require('vn-phone-validator')
phoneValidate('0988888888').validate() // true
phoneValidate('0988 888 888').validate() // true
phoneValidate('84988 888 888').validate() // true
phoneValidate('+84988 888 888').validate() // true
phoneValidate('0123456789').validate() // false
Options
strict: true/false
phoneValidate('0988888888').validate({ strict: true }) // true
phoneValidate('0988 888 888').validate({ strict: true }) // false
format: string
phoneValidate('0988.888.888').validate({ format: 'xxxx.xxx.xxx' }) // true
phoneValidate('0988888888').validate({ format: 'xxxx xxx xxx' }) // false
phoneValidate('0988888888').validate({ format: '097xxxxxx8' }) // false
operator: array (viettel, vinaphone, mobilephone, vietnamobile, gmobile, itelecom)
phoneValidate('0988888888').validate({ operator: ['vietnamobile'] }) // false
Function
operator
Note: Chỉ phát hiện nhà mạng theo đầu số, không phát hiện được nhà mạng nếu số điện thoại đã chuyển mạng giữ số
phoneValidate('0988888888').operator() // viettel
phoneValidate('0123456789').operator() // ''
hidden
phoneValidate('0988888888').hidden(4, '*') // 098888****
format
phoneValidate('0988888888').format('xxxx.xxx.xxx') // 0988.888.888
phoneValidate('0988888888').format('84xxx xxx xxx') // 84988 888 888
Test
$ npm run test
License
MIT
Last updated
Was this helpful?