Skip to content

Commit

Permalink
Merge branch 'master' into update-phone-regex-for-Ghana-en-GH
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin authored Nov 12, 2024
2 parents 885e276 + a066cd2 commit 070007d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function isDate(input, options) {
options = merge(options, default_date_options);
}
if (typeof input === 'string' && isValidFormat(options.format)) {
if (options.strictMode && input.length !== options.format.length) return false;
const formatDelimiter = options.delimiters
.find(delimiter => options.format.indexOf(delimiter) !== -1);
const dateDelimiter = options.strictMode
Expand Down
3 changes: 2 additions & 1 deletion src/lib/isISO6346.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function isISO6346(str) {
} else sum += str[i] * (2 ** i);
}

const checkSumDigit = sum % 11;
let checkSumDigit = sum % 11;
if (checkSumDigit === 10) checkSumDigit = 0;
return Number(str[str.length - 1]) === checkSumDigit;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const phones = {
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'en-ZM': /^(\+?26)?0[79][567]\d{7}$/,
'en-ZW': /^(\+263)[0-9]{9}$/,
'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
Expand Down
53 changes: 53 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8779,13 +8779,16 @@ describe('Validators', () => {
'+260966684590',
'+260976684590',
'260976684590',
'+260779493521',
'+260760010936',
],
invalid: [
'12345',
'',
'Vml2YW11cyBmZXJtZtesting123',
'010-38238383',
'966684590',
'760010936',
],
},
{
Expand Down Expand Up @@ -13065,6 +13068,55 @@ describe('Validators', () => {
});
});

it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
test({
validator: 'isISO6346',
valid: [
'APZU3789870',
'TEMU1002030',
'DFSU1704420',
'CMAU2221480',
'SEGU5060260',
'FCIU8939320',
'TRHU3495670',
'MEDU3871410',
'CMAU2184010',
'TCLU2265970',
],
invalid: [
'APZU3789871', // Incorrect check digit
'TEMU1002031',
'DFSU1704421',
'CMAU2221481',
'SEGU5060261',
],
});
});
it('should validate ISO6346 shipping container IDs with checksum digit 10 represented as 0', () => {
test({
validator: 'isFreightContainerID',
valid: [
'APZU3789870',
'TEMU1002030',
'DFSU1704420',
'CMAU2221480',
'SEGU5060260',
'FCIU8939320',
'TRHU3495670',
'MEDU3871410',
'CMAU2184010',
'TCLU2265970',
],
invalid: [
'APZU3789871', // Incorrect check digit
'TEMU1002031',
'DFSU1704421',
'CMAU2221481',
'SEGU5060261',
],
});
});

// EU-UK valid numbers sourced from https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx or constructed by @tplessas.
it('should validate taxID', () => {
test({
Expand Down Expand Up @@ -14000,6 +14052,7 @@ describe('Validators', () => {
new Date([2014, 2, 15]),
new Date('2014-03-15'),
'29.02.2020',
'02.29.2020.20',
'2024-',
'2024-05',
'2024-05-',
Expand Down

0 comments on commit 070007d

Please sign in to comment.