rut-regex
Version:
Regular expression for matching Chile RUTs
10 lines (7 loc) • 329 B
JavaScript
module.exports = options => {
options = Object.assign({dot: true, hyphen: true}, options)
const dot = options.dot ? '\\.' : '\\.?'
const hyphen = options.hyphen ? '-' : '-?'
const regex = `0*(\\d{1,3}(${dot}\\d{3})*)${hyphen}([\\dkK])`
return options.exact ? new RegExp(`^${regex}$`, 'i') : new RegExp(regex, 'ig')
}