-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for IL in isIdentityCard() #1041
Changes from 6 commits
ae5480d
d0075d4
8f1ad81
98e8a90
10c724a
36ced81
3139792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,31 @@ const validators = { | |
|
||
return sanitized.endsWith(controlDigits[number % 23]); | ||
}, | ||
IL: (str) => { | ||
const DNI = /^\d+$/; | ||
|
||
// sanitize user input | ||
const sanitized = str.trim(); | ||
|
||
// validate the data structure | ||
if (!DNI.test(sanitized)) { | ||
return false; | ||
} | ||
|
||
const id = sanitized; | ||
|
||
if (id.length !== 9 || isNaN(id)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @profnandaa isn't this check unnecessary if we add the size limit in the regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that's true. That was oversight from my end. You can do a quick update PR on this?
cc. @perimiter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats true, but you still need the if statement for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @perimiter your regex is searching only for digits, the function will always exit before the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// Make sure ID is formatted properly | ||
return false; | ||
} | ||
let sum = 0, | ||
incNum; | ||
for (let i = 0; i < id.length; i++) { | ||
incNum = Number(id[i]) * ((i % 2) + 1); // Multiply number by 1 or 2 | ||
sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total | ||
} | ||
return sum % 10 === 0; | ||
}, | ||
'zh-TW': (str) => { | ||
const ALPHABET_CODES = { | ||
A: 10, | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@perimiter - we should be good now. However, I missed out this one. Please change the locale to
he-IL
here and in the other files, then we should be good to go.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As used in
isMobilePhone
and also see here for ref