Skip to content

Commit bc48acd

Browse files
authored
Merge pull request #19 from Ukarus/bugfix/validation_with_0
bugfix: does not validate ruts that starts with 0
2 parents b32a28d + e523b9b commit bc48acd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ function validate (rut) {
1010
if (typeof rut !== 'string') {
1111
return false
1212
}
13+
14+
// if it starts with 0 we return false
15+
// so a rut like 00000000-0 will not pass
16+
if (/^0+/.test(rut)) {
17+
return false;
18+
}
19+
1320
if (!/^0*(\d{1,3}(\.?\d{3})*)-?([\dkK])$/.test(rut)) {
1421
return false
1522
}

test.js

+7
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ test('format', t => {
3636
t.is(format('18*972*631*7'), '18.972.631-7')
3737
t.is(format('9068826-k'), '9.068.826-K')
3838
})
39+
40+
test('does not validate rut with 0 on most right digit', t => {
41+
t.false(validate('00.000.000-0'))
42+
t.false(validate('00000000-0'))
43+
t.false(validate('0000000000000000000000-0'))
44+
})
45+

0 commit comments

Comments
 (0)