Skip to content

Commit

Permalink
Merge pull request #28 from jlobos/vives-jujuists
Browse files Browse the repository at this point in the history
Algunas mejoras
  • Loading branch information
jlobos authored Jun 25, 2024
2 parents 2cad702 + a35e1a4 commit 2c40558
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ function validate (rut) {
return false
}

// if it starts with 0 we return false
// so a rut like 00000000-0 will not pass
if (/^0+/.test(rut)) {
return false
}

if (!/^0*(\d{1,3}(\.?\d{3})*)-?([\dkK])$/.test(rut)) {
if (!/^([1-9]\d{0,2}(\.?\d{3})*)-?[\dkK]$/.test(rut)) {
return false
}

Expand All @@ -37,6 +31,9 @@ function validate (rut) {
function format (rut, options = {
dots: true
}) {
// If the input is not a string, return an empty string
if (!rut) { return '' }

rut = clean(rut)

let result
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test('format', (t) => {
t.is(format('189726317', { dots: false }), '18972631-7')
t.is(format('18*972*631*7', { dots: false }), '18972631-7')
t.is(format('9068826-k', { dots: false }), '9068826-K')
t.is(format(''), '')
})

test('does not validate rut with 0 on most right digit', t => {
Expand Down

0 comments on commit 2c40558

Please sign in to comment.