diff --git a/README.md b/README.md index c8f66c7..c2b1733 100644 --- a/README.md +++ b/README.md @@ -17,30 +17,30 @@ This package includes various categorised validators which can be helppful for v ### Identification and Financial Numbers: 1. **Credit Card Number**: Validate using the Luhn algorithm. -2. **Passport Number**: Support formats for multiple countries. (Upcoming) +2. **Passport Number**: Support formats for multiple countries. 3. **Aadhaar**: Validites Indian Identity numbers using specific patterns. -4. **TIN/EIN**: Validate Taxpayer Identification Number (TIN) or Employer Identification Number (EIN). (Upcoming) +4. **TIN/EIN**: Validate Taxpayer Identification Number (TIN) or Employer Identification Number (EIN). ### Contact Information: 5. **Postal/ZIP Code**: Validate based on country-specific formats. It supports top 25 countries based on ISO 3166-1 alpha-2 codes namely: US, CN, IN, ID, PK, BR, NG, BD, RU, MX, JP, ET, PH, EG, VN, CD, TR, IR, DE, TH, GB, FR, IT, TZ, ZA. ### Personal Information: -6. **Date of Birth**: Validate format and ensure the person’s age falls within a reasonable range. (Upcoming) -7. **Email**: Validate email addresses which conform to standard formats. +6. **Email**: Validate email addresses which conform to standard formats. ### Internet/Network: -8. **IP Address**: Validate IPv4 and IPv6 formats. -9. **URL**: Validate structure and it supports URLs with and without protocols, and it handles query parameters and fragments. -10. **MAC Address**: Validate for networking hardware.(Upcoming) +7. **IP Address**: Validate IPv4 and IPv6 formats. +8. **URL**: Validate structure and it supports URLs with and without protocols, and it handles query parameters and fragments. +9. **MAC Address**: Validate for networking hardware. ### Document Validation: -11. **PAN (Permanent Account Number)**: For Indian tax records.(Upcoming) -12. **Social Security Number (SSN)**: Validates U.S. Social Security Numbers based on predefined rules. -13. **Social Insurance Number (SIN)**: For Canada or equivalent in other countries. (Upcoming) +10. **PAN (Permanent Account Number)**: For Indian tax records. +11. **Social Security Number (SSN)**: Validates U.S. Social Security Numbers based on predefined rules. +12. **Social Insurance Number (SIN)**: For Canada or equivalent in other countries. ### Formats and Patterns: -14. **File Extensions**: Validate file names/extensions (e.g., `.jpg`, `.pdf`). +13. **File Extensions**: Validate file names/extensions (e.g., `.jpg`, `.pdf`). ### Additional Utility: -15. **Hex Color Codes**: Validate `#RRGGBB` or `#RGB` color formats. -16. **EAN/UPC**: Validate international product codes. (Upcoming) +14. **Hex Color Codes**: Validate `#RRGGBB` or `#RGB` color formats. +15. **EAN/UPC**: Validate international product codes. +16. **Base64**: Validate for Base64 encoded string. diff --git a/USAGE_DETAILS.md b/USAGE_DETAILS.md index 094c93a..fae8279 100644 --- a/USAGE_DETAILS.md +++ b/USAGE_DETAILS.md @@ -31,8 +31,7 @@ console.log(isValid_Aadhaar_Number(aadhaarNumber)); // Output: true if valid, fa ```typescript import { isValid_Credit_Card } from 'validate-functions/credit-card'; - -const creditCardNumber = '4539 1488 0343 6467'; // Example of a valid Visa card number +valid Visa card number console.log(isValid_Credit_Card(creditCardNumber)); // Output: true if valid, false otherwise ``` @@ -59,17 +58,15 @@ console.log(isValid_IPv6(ipv6Address)); // Output: true if valid, false otherwis ```typescript import { isValid_Hex_Color } from 'validate-functions/hex-code'; -const hexColor = '#abc'; // Example of a valid 3-digit hex color console.log(isValid_Hex_Color(hexColor)); // Output: true if valid, false otherwise -const hexColor6 = '#abcdef'; // Example of a valid 6-digit hex color console.log(isValid_Hex_Color(hexColor6)); // Output: true if valid, false otherwise ``` - **isValid_Postal_Code** ```typescript -import { isValid_Postal_Code, CountryCode } from 'validate-functions/postal-zip'; +import { isValid_Postal_Code, CountryCode } from 'validate-functions/postal'; // India const indianPostalCode = '110001'; @@ -81,7 +78,6 @@ console.log(isValid_Postal_Code(indianPostalCode, CountryCode.IN)); // Output: t ```typescript import { isValid_URL } from 'validate-functions/url'; -// Example of a URL with query parameters const urlWithQuery = 'http://example.com?name=value'; console.log(isValid_URL(urlWithQuery)); // Output: true ``` @@ -91,8 +87,72 @@ console.log(isValid_URL(urlWithQuery)); // Output: true ```typescript import { isValid_File_Extension } from 'validate-functions/file-extension'; -// Example of checking a file extension const fileName = 'document.pdf'; const allowedExtensions = ['pdf', 'doc', 'txt']; console.log(isValid_File_Extension(fileName, allowedExtensions)); // Output: true if the extension is valid, false otherwise +``` + +- **isValid_Base64** + +```typescript +import { isValid_Base64 } from 'validate-functions/base64'; + +const base64String = 'U29mdHdhcmUgRW5naW5lZXJpbmc='; +console.log(isValid_Base64(base64String)); // Output: true if valid, false otherwise +``` + +- **isValid_EAN_UPC** + +```typescript +import { isValid_EAN_UPC } from 'validate-functions/ean-uac-code'; + +const eanUpcCode = '123456789012'; +console.log(isValid_EAN_UPC(eanUpcCode)); // Output: true if valid, false otherwise +``` + +- **isValid_MAC_Address** + +```typescript +import { isValid_MAC_Address } from 'validate-functions/mac-address'; + +const macAddress = '01:23:45:67:89:AB'; +console.log(isValid_MAC_Address(macAddress)); // Output: true if valid, false otherwise +``` + +- **isValid_PAN** + +```typescript +import { isValid_PAN } from 'validate-functions/pan'; + +const panNumber = 'ABCDE1234F'; +console.log(isValid_PAN(panNumber)); // Output: true if valid, false otherwise +``` + +- **isValid_SIN** + +```typescript +import { isValid_SIN } from 'validate-functions/sin'; + +const sinNumber = '123 456 782'; +console.log(isValid_SIN(sinNumber)); // Output: true if valid, false otherwise +``` + +- **isValid_TIN** + +```typescript +import { isValid_TIN, CountryCode } from 'validate-functions/tin'; + +// Example for USA +const einNumber = '12-3456789'; +console.log(isValid_TIN(einNumber, CountryCode.USA)); // Output: true if valid, false otherwise +``` + +- **isValid_Passport_Number** + +```typescript +import { isValid_Passport_Number, CountryCode } from 'validate-functions/passport-number'; + +// Example for USA +const passportNumber = 'A1234567'; +console.log(isValid_Passport_Number(passportNumber, CountryCode.USA)); // Output: true if valid, false otherwise ``` \ No newline at end of file diff --git a/src/__tests__/base64.test.ts b/src/__tests__/base64.test.ts new file mode 100644 index 0000000..676028e --- /dev/null +++ b/src/__tests__/base64.test.ts @@ -0,0 +1,33 @@ +import { isValid_Base64 } from '../base64'; + +describe('Base64 Validation', () => { + it('should return true for a valid Base64 string', () => { + const validBase64 = 'U29mdHdhcmUgRW5naW5lZXJpbmc='; + expect(isValid_Base64(validBase64)).toBe(true); + }); + + it('should return true for a valid Base64 string with padding', () => { + const validBase64WithPadding = 'U29mdHdhcmU='; + expect(isValid_Base64(validBase64WithPadding)).toBe(true); + }); + + it('should return false for an invalid Base64 string with invalid characters', () => { + const invalidBase64 = 'U29mdHdhcmU$'; + expect(isValid_Base64(invalidBase64)).toBe(false); + }); + + it('should return false for a string with incorrect Base64 padding', () => { + const incorrectPadding = 'U29mdHdhcmU=='; + expect(isValid_Base64(incorrectPadding)).toBe(false); + }); + + it('should return true for an empty string (considered valid Base64)', () => { + const emptyString = ''; + expect(isValid_Base64(emptyString)).toBe(true); + }); + + it('should return false for a non-Base64 string', () => { + const nonBase64 = 'Hello, World!'; + expect(isValid_Base64(nonBase64)).toBe(false); + }); +}); diff --git a/src/__tests__/ean-uac-code.test.ts b/src/__tests__/ean-uac-code.test.ts new file mode 100644 index 0000000..a705a6a --- /dev/null +++ b/src/__tests__/ean-uac-code.test.ts @@ -0,0 +1,38 @@ +import { isValid_EAN_UPC } from '../ean-uac-code'; + +describe('EAN/UPC Code Validation', () => { + it('should return true for a valid 8-digit UPC code', () => { + const validUPC8 = '12345678'; + expect(isValid_EAN_UPC(validUPC8)).toBe(true); + }); + + it('should return true for a valid 12-digit UPC code', () => { + const validUPC12 = '123456789012'; + expect(isValid_EAN_UPC(validUPC12)).toBe(true); + }); + + it('should return true for a valid 13-digit EAN code', () => { + const validEAN13 = '1234567890123'; + expect(isValid_EAN_UPC(validEAN13)).toBe(true); + }); + + it('should return false for a code with less than 8 digits', () => { + const shortCode = '1234567'; + expect(isValid_EAN_UPC(shortCode)).toBe(false); + }); + + it('should return false for a code with more than 13 digits', () => { + const longCode = '12345678901234'; + expect(isValid_EAN_UPC(longCode)).toBe(false); + }); + + it('should return false for a code with non-numeric characters', () => { + const nonNumericCode = '12345A789012'; + expect(isValid_EAN_UPC(nonNumericCode)).toBe(false); + }); + + it('should return false for an empty string', () => { + const emptyString = ''; + expect(isValid_EAN_UPC(emptyString)).toBe(false); + }); +}); diff --git a/src/__tests__/mac-address.test.ts b/src/__tests__/mac-address.test.ts new file mode 100644 index 0000000..a4a8869 --- /dev/null +++ b/src/__tests__/mac-address.test.ts @@ -0,0 +1,33 @@ +import { isValid_MAC_Address } from '../mac-address'; + +describe('MAC Address Validation', () => { + it('should return true for a valid MAC address', () => { + const validMAC = '01:23:45:67:89:AB'; + expect(isValid_MAC_Address(validMAC)).toBe(true); + }); + + it('should return true for a valid MAC address with lowercase letters', () => { + const validMACLower = '01:23:45:67:89:ab'; + expect(isValid_MAC_Address(validMACLower)).toBe(true); + }); + + it('should return false for a MAC address with invalid characters', () => { + const invalidMACChars = '01:23:45:67:89:ZZ'; + expect(isValid_MAC_Address(invalidMACChars)).toBe(false); + }); + + it('should return false for a MAC address with incorrect length', () => { + const shortMAC = '01:23:45:67:89'; + expect(isValid_MAC_Address(shortMAC)).toBe(false); + }); + + it('should return false for a MAC address with incorrect delimiter', () => { + const invalidDelimiterMAC = '01-23-45-67-89-AB'; + expect(isValid_MAC_Address(invalidDelimiterMAC)).toBe(false); + }); + + it('should return false for an empty string', () => { + const emptyString = ''; + expect(isValid_MAC_Address(emptyString)).toBe(false); + }); +}); diff --git a/src/__tests__/pan.test.ts b/src/__tests__/pan.test.ts new file mode 100644 index 0000000..a796ba2 --- /dev/null +++ b/src/__tests__/pan.test.ts @@ -0,0 +1,33 @@ +import { isValid_PAN } from '../pan'; + +describe('PAN Validation', () => { + it('should return true for a valid PAN', () => { + const validPAN = 'ABCDE1234F'; + expect(isValid_PAN(validPAN)).toBe(true); + }); + + it('should return false for a PAN with incorrect letter count', () => { + const invalidPANLetters = 'ABCD1234F'; + expect(isValid_PAN(invalidPANLetters)).toBe(false); + }); + + it('should return false for a PAN with incorrect digit count', () => { + const invalidPANDigits = 'ABCDE123F'; + expect(isValid_PAN(invalidPANDigits)).toBe(false); + }); + + it('should return false for a PAN with lowercase letters', () => { + const invalidPANLowercase = 'abcde1234f'; + expect(isValid_PAN(invalidPANLowercase)).toBe(false); + }); + + it('should return false for a PAN with special characters', () => { + const invalidPANSpecialChars = 'ABCD@1234F'; + expect(isValid_PAN(invalidPANSpecialChars)).toBe(false); + }); + + it('should return false for an empty string', () => { + const emptyString = ''; + expect(isValid_PAN(emptyString)).toBe(false); + }); +}); diff --git a/src/__tests__/passport-number.test.ts b/src/__tests__/passport-number.test.ts new file mode 100644 index 0000000..66a2a53 --- /dev/null +++ b/src/__tests__/passport-number.test.ts @@ -0,0 +1,140 @@ +import { + isValid_Passport_Number, + PassportCountryCode, +} from '../passport-number'; + +describe('Passport Number Validation', () => { + const testCases = [ + { country: PassportCountryCode.USA, valid: 'A1234567', invalid: '12345' }, + { + country: PassportCountryCode.CAN, + valid: 'AB123456', + invalid: 'A1234567', + }, + { + country: PassportCountryCode.GBR, + valid: '123456789', + invalid: '12345678', + }, + { + country: PassportCountryCode.AUS, + valid: 'A1234567', + invalid: '12345678', + }, + { + country: PassportCountryCode.IND, + valid: 'A-1234567', + invalid: '12345678', + }, + { + country: PassportCountryCode.DEU, + valid: 'C12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.FRA, + valid: '12AB34567', + invalid: '12345678', + }, + { + country: PassportCountryCode.CHN, + valid: 'E12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.JPN, + valid: 'AB1234567', + invalid: '12345678', + }, + { + country: PassportCountryCode.RUS, + valid: '123456789', + invalid: '12345678', + }, + { + country: PassportCountryCode.BRA, + valid: 'AB123456', + invalid: '12345678', + }, + { + country: PassportCountryCode.ITA, + valid: 'A12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.MEX, + valid: '123456789', + invalid: '12345678', + }, + { + country: PassportCountryCode.ZAF, + valid: 'A12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.KOR, + valid: 'A12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.SGP, + valid: 'S1234567A', + invalid: 'S12345678A', + }, + { + country: PassportCountryCode.NLD, + valid: 'A12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.ESP, + valid: 'ABC123456', + invalid: '12345678', + }, + { + country: PassportCountryCode.ARG, + valid: 'ABC123456', + invalid: '12345678', + }, + { + country: PassportCountryCode.TUR, + valid: 'AB1234567', + invalid: '12345678', + }, + { + country: PassportCountryCode.SAU, + valid: 'A12345678', + invalid: '12345678', + }, + { + country: PassportCountryCode.UAE, + valid: '123456789', + invalid: '12345678', + }, + { + country: PassportCountryCode.SWE, + valid: 'A1B2C3D4E', + invalid: 'ABCD1234567', + }, + { + country: PassportCountryCode.CHE, + valid: 'C1234567', + invalid: 'C12#4567', + }, + { + country: PassportCountryCode.BEL, + valid: 'AB123456', + invalid: '12345678', + }, + ]; + + testCases.forEach(({ country, valid, invalid }) => { + it(`should return true for a valid ${country} passport number`, () => { + expect(isValid_Passport_Number(valid, country)).toBe(true); + }); + + it(`should return false for an invalid ${country} passport number`, () => { + expect(isValid_Passport_Number(invalid, country)).toBe(false); + }); + }); +}); diff --git a/src/__tests__/postal-zip.test.ts b/src/__tests__/postal.test.ts similarity index 55% rename from src/__tests__/postal-zip.test.ts rename to src/__tests__/postal.test.ts index aff6612..01af96d 100644 --- a/src/__tests__/postal-zip.test.ts +++ b/src/__tests__/postal.test.ts @@ -1,263 +1,271 @@ -import { isValid_Postal_Code, CountryCode } from '../postal-zip'; +import { isValid_Postal_Code, PostalCountryCode } from '../postal'; describe('Postal Code Validation', () => { describe('United States', () => { it('should return true for a valid 5-digit US postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.US)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.US)).toBe(true); }); it('should return true for a valid 9-digit US postal code', () => { - expect(isValid_Postal_Code('12345-6789', CountryCode.US)).toBe(true); + expect(isValid_Postal_Code('12345-6789', PostalCountryCode.US)).toBe( + true + ); }); it('should return false for an invalid US postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.US)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.US)).toBe(false); }); }); describe('China', () => { it('should return true for a valid Chinese postal code', () => { - expect(isValid_Postal_Code('100000', CountryCode.CN)).toBe(true); + expect(isValid_Postal_Code('100000', PostalCountryCode.CN)).toBe(true); }); it('should return false for an invalid Chinese postal code', () => { - expect(isValid_Postal_Code('10000', CountryCode.CN)).toBe(false); + expect(isValid_Postal_Code('10000', PostalCountryCode.CN)).toBe(false); }); }); describe('India', () => { it('should return true for a valid Indian postal code', () => { - expect(isValid_Postal_Code('110001', CountryCode.IN)).toBe(true); + expect(isValid_Postal_Code('110001', PostalCountryCode.IN)).toBe(true); }); it('should return false for an invalid Indian postal code', () => { - expect(isValid_Postal_Code('11000', CountryCode.IN)).toBe(false); + expect(isValid_Postal_Code('11000', PostalCountryCode.IN)).toBe(false); }); }); describe('Indonesia', () => { it('should return true for a valid Indonesian postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.ID)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.ID)).toBe(true); }); it('should return false for an invalid Indonesian postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.ID)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.ID)).toBe(false); }); }); describe('Pakistan', () => { it('should return true for a valid Pakistani postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.PK)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.PK)).toBe(true); }); it('should return false for an invalid Pakistani postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.PK)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.PK)).toBe(false); }); }); describe('Brazil', () => { it('should return true for a valid Brazilian postal code', () => { - expect(isValid_Postal_Code('01000-000', CountryCode.BR)).toBe(true); + expect(isValid_Postal_Code('01000-000', PostalCountryCode.BR)).toBe(true); }); it('should return false for an invalid Brazilian postal code', () => { - expect(isValid_Postal_Code('01000000', CountryCode.BR)).toBe(false); + expect(isValid_Postal_Code('01000000', PostalCountryCode.BR)).toBe(false); }); }); describe('Nigeria', () => { it('should return true for a valid Nigerian postal code', () => { - expect(isValid_Postal_Code('123456', CountryCode.NG)).toBe(true); + expect(isValid_Postal_Code('123456', PostalCountryCode.NG)).toBe(true); }); it('should return false for an invalid Nigerian postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.NG)).toBe(false); + expect(isValid_Postal_Code('12345', PostalCountryCode.NG)).toBe(false); }); }); describe('Bangladesh', () => { it('should return true for a valid Bangladeshi postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.BD)).toBe(true); + expect(isValid_Postal_Code('1234', PostalCountryCode.BD)).toBe(true); }); it('should return false for an invalid Bangladeshi postal code', () => { - expect(isValid_Postal_Code('123', CountryCode.BD)).toBe(false); + expect(isValid_Postal_Code('123', PostalCountryCode.BD)).toBe(false); }); }); describe('Russia', () => { it('should return true for a valid Russian postal code', () => { - expect(isValid_Postal_Code('123456', CountryCode.RU)).toBe(true); + expect(isValid_Postal_Code('123456', PostalCountryCode.RU)).toBe(true); }); it('should return false for an invalid Russian postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.RU)).toBe(false); + expect(isValid_Postal_Code('12345', PostalCountryCode.RU)).toBe(false); }); }); describe('Mexico', () => { it('should return true for a valid Mexican postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.MX)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.MX)).toBe(true); }); it('should return false for an invalid Mexican postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.MX)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.MX)).toBe(false); }); }); describe('Japan', () => { it('should return true for a valid Japanese postal code', () => { - expect(isValid_Postal_Code('123-4567', CountryCode.JP)).toBe(true); + expect(isValid_Postal_Code('123-4567', PostalCountryCode.JP)).toBe(true); }); it('should return false for an invalid Japanese postal code', () => { - expect(isValid_Postal_Code('1234567', CountryCode.JP)).toBe(false); + expect(isValid_Postal_Code('1234567', PostalCountryCode.JP)).toBe(false); }); }); describe('Ethiopia', () => { it('should return true for a valid Ethiopian postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.ET)).toBe(true); + expect(isValid_Postal_Code('1234', PostalCountryCode.ET)).toBe(true); }); it('should return false for an invalid Ethiopian postal code', () => { - expect(isValid_Postal_Code('123', CountryCode.ET)).toBe(false); + expect(isValid_Postal_Code('123', PostalCountryCode.ET)).toBe(false); }); }); describe('Philippines', () => { it('should return true for a valid Philippine postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.PH)).toBe(true); + expect(isValid_Postal_Code('1234', PostalCountryCode.PH)).toBe(true); }); it('should return false for an invalid Philippine postal code', () => { - expect(isValid_Postal_Code('123', CountryCode.PH)).toBe(false); + expect(isValid_Postal_Code('123', PostalCountryCode.PH)).toBe(false); }); }); describe('Egypt', () => { it('should return true for a valid Egyptian postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.EG)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.EG)).toBe(true); }); it('should return false for an invalid Egyptian postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.EG)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.EG)).toBe(false); }); }); describe('Vietnam', () => { it('should return true for a valid Vietnamese postal code', () => { - expect(isValid_Postal_Code('123456', CountryCode.VN)).toBe(true); + expect(isValid_Postal_Code('123456', PostalCountryCode.VN)).toBe(true); }); it('should return false for an invalid Vietnamese postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.VN)).toBe(false); + expect(isValid_Postal_Code('12345', PostalCountryCode.VN)).toBe(false); }); }); describe('Democratic Republic of the Congo', () => { it('should return true for a valid Congolese postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.CD)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.CD)).toBe(true); }); it('should return false for an invalid Congolese postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.CD)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.CD)).toBe(false); }); }); describe('Turkey', () => { it('should return true for a valid Turkish postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.TR)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.TR)).toBe(true); }); it('should return false for an invalid Turkish postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.TR)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.TR)).toBe(false); }); }); describe('Iran', () => { it('should return true for a valid Iranian postal code', () => { - expect(isValid_Postal_Code('1234567890', CountryCode.IR)).toBe(true); + expect(isValid_Postal_Code('1234567890', PostalCountryCode.IR)).toBe( + true + ); }); it('should return false for an invalid Iranian postal code', () => { - expect(isValid_Postal_Code('123456789', CountryCode.IR)).toBe(false); + expect(isValid_Postal_Code('123456789', PostalCountryCode.IR)).toBe( + false + ); }); }); describe('Germany', () => { it('should return true for a valid German postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.DE)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.DE)).toBe(true); }); it('should return false for an invalid German postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.DE)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.DE)).toBe(false); }); }); describe('Thailand', () => { it('should return true for a valid Thai postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.TH)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.TH)).toBe(true); }); it('should return false for an invalid Thai postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.TH)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.TH)).toBe(false); }); }); describe('United Kingdom', () => { it('should return true for a valid UK postal code', () => { - expect(isValid_Postal_Code('W1A 1AA', CountryCode.GB)).toBe(true); + expect(isValid_Postal_Code('W1A 1AA', PostalCountryCode.GB)).toBe(true); }); it('should return false for an invalid UK postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.GB)).toBe(false); + expect(isValid_Postal_Code('12345', PostalCountryCode.GB)).toBe(false); }); }); describe('France', () => { it('should return true for a valid French postal code', () => { - expect(isValid_Postal_Code('75001', CountryCode.FR)).toBe(true); + expect(isValid_Postal_Code('75001', PostalCountryCode.FR)).toBe(true); }); it('should return false for an invalid French postal code', () => { - expect(isValid_Postal_Code('7500', CountryCode.FR)).toBe(false); + expect(isValid_Postal_Code('7500', PostalCountryCode.FR)).toBe(false); }); }); describe('Italy', () => { it('should return true for a valid Italian postal code', () => { - expect(isValid_Postal_Code('00100', CountryCode.IT)).toBe(true); + expect(isValid_Postal_Code('00100', PostalCountryCode.IT)).toBe(true); }); it('should return false for an invalid Italian postal code', () => { - expect(isValid_Postal_Code('0010', CountryCode.IT)).toBe(false); + expect(isValid_Postal_Code('0010', PostalCountryCode.IT)).toBe(false); }); }); describe('Tanzania', () => { it('should return true for a valid Tanzanian postal code', () => { - expect(isValid_Postal_Code('12345', CountryCode.TZ)).toBe(true); + expect(isValid_Postal_Code('12345', PostalCountryCode.TZ)).toBe(true); }); it('should return false for an invalid Tanzanian postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.TZ)).toBe(false); + expect(isValid_Postal_Code('1234', PostalCountryCode.TZ)).toBe(false); }); }); describe('South Africa', () => { it('should return true for a valid South African postal code', () => { - expect(isValid_Postal_Code('1234', CountryCode.ZA)).toBe(true); + expect(isValid_Postal_Code('1234', PostalCountryCode.ZA)).toBe(true); }); it('should return false for an invalid South African postal code', () => { - expect(isValid_Postal_Code('123', CountryCode.ZA)).toBe(false); + expect(isValid_Postal_Code('123', PostalCountryCode.ZA)).toBe(false); }); }); describe('Invalid Country Code', () => { it('should return false for an unsupported country code', () => { - expect(isValid_Postal_Code('awea23s', 'UN' as CountryCode)).toBe(false); + expect(isValid_Postal_Code('awea23s', 'UN' as PostalCountryCode)).toBe( + false + ); }); }); }); diff --git a/src/__tests__/sin.test.ts b/src/__tests__/sin.test.ts new file mode 100644 index 0000000..87f1201 --- /dev/null +++ b/src/__tests__/sin.test.ts @@ -0,0 +1,43 @@ +import { isValid_SIN } from '../sin'; + +describe('Social Insurance Number (SIN) Validation', () => { + it('should return true for a valid SIN without spaces or dashes', () => { + const validSIN = '123456782'; + expect(isValid_SIN(validSIN)).toBe(true); + }); + + it('should return true for a valid SIN with spaces', () => { + const validSINWithSpaces = '123 456 782'; + expect(isValid_SIN(validSINWithSpaces)).toBe(true); + }); + + it('should return true for a valid SIN with dashes', () => { + const validSINWithDashes = '123-456-782'; + expect(isValid_SIN(validSINWithDashes)).toBe(true); + }); + + it('should return false for an invalid SIN with incorrect check digit', () => { + const invalidSIN = '123456789'; + expect(isValid_SIN(invalidSIN)).toBe(false); + }); + + it('should return false for a SIN with non-numeric characters', () => { + const nonNumericSIN = '123A56782'; + expect(isValid_SIN(nonNumericSIN)).toBe(false); + }); + + it('should return false for a SIN with less than 9 digits', () => { + const shortSIN = '12345678'; + expect(isValid_SIN(shortSIN)).toBe(false); + }); + + it('should return false for a SIN with more than 9 digits', () => { + const longSIN = '1234567890'; + expect(isValid_SIN(longSIN)).toBe(false); + }); + + it('should return false for an empty string', () => { + const emptyString = ''; + expect(isValid_SIN(emptyString)).toBe(false); + }); +}); diff --git a/src/__tests__/tin.test.ts b/src/__tests__/tin.test.ts new file mode 100644 index 0000000..8cc4e4c --- /dev/null +++ b/src/__tests__/tin.test.ts @@ -0,0 +1,52 @@ +import { isValid_TIN, ICountryCode } from '../tin'; + +describe('TIN Validation', () => { + const testCases = [ + { country: ICountryCode.USA, valid: '12-3456789', invalid: '123456789' }, + { country: ICountryCode.CAN, valid: '123456789', invalid: '12345678' }, + { country: ICountryCode.GBR, valid: '123456789', invalid: '12345678' }, + { country: ICountryCode.AUS, valid: '123456789', invalid: '12345678' }, + { country: ICountryCode.IND, valid: 'ABCDE1234F', invalid: '123456789' }, + { country: ICountryCode.DEU, valid: '12345678901', invalid: '123456789' }, + { country: ICountryCode.FRA, valid: '1234567890123', invalid: '123456789' }, + { + country: ICountryCode.CHN, + valid: '123456789012345', + invalid: '123456789', + }, + { country: ICountryCode.JPN, valid: '123456789012', invalid: '123456789' }, + { country: ICountryCode.RUS, valid: '1234567890', invalid: '123456789' }, + { country: ICountryCode.BRA, valid: '12345678901', invalid: '123456789' }, + { + country: ICountryCode.ITA, + valid: 'RSSMRA85M01H501Z', + invalid: '123456789', + }, + { country: ICountryCode.MEX, valid: 'ABCD123456XYZ', invalid: '123456789' }, + { country: ICountryCode.ZAF, valid: '1234567890', invalid: '123456789' }, + { country: ICountryCode.SGP, valid: '12345678A', invalid: '123456789' }, + { country: ICountryCode.NLD, valid: '123456789', invalid: '12345678' }, + { country: ICountryCode.ESP, valid: 'A12345678', invalid: '123456789' }, + { country: ICountryCode.ARG, valid: '12345678901', invalid: '123456789' }, + { country: ICountryCode.TUR, valid: '1234567890', invalid: '123456789' }, + { country: ICountryCode.SAU, valid: '1234567890', invalid: '123456789' }, + { + country: ICountryCode.UAE, + valid: '123456789012345', + invalid: '123456789', + }, + { country: ICountryCode.SWE, valid: '1234567890', invalid: '123456789' }, + { country: ICountryCode.CHE, valid: '123456789', invalid: '12345678' }, + { country: ICountryCode.BEL, valid: '12345678901', invalid: '123456789' }, + ]; + + testCases.forEach(({ country, valid, invalid }) => { + it(`should return true for a valid ${country} TIN/EIN`, () => { + expect(isValid_TIN(valid, country)).toBe(true); + }); + + it(`should return false for an invalid ${country} TIN/EIN`, () => { + expect(isValid_TIN(invalid, country)).toBe(false); + }); + }); +}); diff --git a/src/base64.ts b/src/base64.ts new file mode 100644 index 0000000..fccc7aa --- /dev/null +++ b/src/base64.ts @@ -0,0 +1,10 @@ +/** + * Base64 String Validation + * @param base64 + * @returns + */ +export const isValid_Base64 = (base64: string): boolean => { + const base64Regex = + /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$/; + return base64Regex.test(base64); +}; diff --git a/src/ean-uac-code.ts b/src/ean-uac-code.ts new file mode 100644 index 0000000..a4f2156 --- /dev/null +++ b/src/ean-uac-code.ts @@ -0,0 +1,9 @@ +/** + * EAN/UPC Code Validation + * @param code + * @returns + */ +export const isValid_EAN_UPC = (code: string): boolean => { + const eanUpcRegex = /^(?:\d{8}|\d{12,13})$/; + return eanUpcRegex.test(code); +}; diff --git a/src/index.ts b/src/index.ts index e61c75b..bb685e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,16 @@ export * from './aadhaar'; +export * from './base64'; export * from './credit-card'; +export * from './ean-uac-code'; export * from './email'; export * from './file-extension'; -export * from './ip'; export * from './hex-color'; -export * from './postal-zip'; +export * from './ip'; +export * from './mac-address'; +export * from './pan'; +export * from './passport-number'; +export * from './postal'; +export * from './sin'; export * from './ssn'; +export * from './tin'; export * from './url'; diff --git a/src/mac-address.ts b/src/mac-address.ts new file mode 100644 index 0000000..32f4119 --- /dev/null +++ b/src/mac-address.ts @@ -0,0 +1,9 @@ +/** + * MAC Address Validation + * @param mac + * @returns + */ +export const isValid_MAC_Address = (mac: string): boolean => { + const macRegex = /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/; + return macRegex.test(mac); +}; diff --git a/src/pan.ts b/src/pan.ts new file mode 100644 index 0000000..3723207 --- /dev/null +++ b/src/pan.ts @@ -0,0 +1,9 @@ +/** + * PAN (Permanent Account Number) Validation + * @param pan + * @returns + */ +export const isValid_PAN = (pan: string): boolean => { + const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/; + return panRegex.test(pan); +}; diff --git a/src/passport-number.ts b/src/passport-number.ts new file mode 100644 index 0000000..6d007f1 --- /dev/null +++ b/src/passport-number.ts @@ -0,0 +1,69 @@ +export enum PassportCountryCode { + USA = 'USA', + CAN = 'CAN', + GBR = 'GBR', + AUS = 'AUS', + IND = 'IND', + DEU = 'DEU', + FRA = 'FRA', + CHN = 'CHN', + JPN = 'JPN', + RUS = 'RUS', + BRA = 'BRA', + ITA = 'ITA', + MEX = 'MEX', + ZAF = 'ZAF', + KOR = 'KOR', + SGP = 'SGP', + NLD = 'NLD', + ESP = 'ESP', + ARG = 'ARG', + TUR = 'TUR', + SAU = 'SAU', + UAE = 'UAE', + SWE = 'SWE', + CHE = 'CHE', + BEL = 'BEL', +} + +/** + * Passport Number Validation + * @param passportNumber + * @param countryCode + * @returns + */ +export const isValid_Passport_Number = ( + passportNumber: string, + countryCode: PassportCountryCode +): boolean => { + const passportRegexes: { [key in PassportCountryCode]: RegExp } = { + [PassportCountryCode.USA]: /^[a-zA-Z0-9]{6,9}$/, + [PassportCountryCode.CAN]: /^[A-Z]{2}\d{6}$/, + [PassportCountryCode.GBR]: /^\d{9}$/, + [PassportCountryCode.AUS]: /^[A-Z]\d{7}$/, + [PassportCountryCode.IND]: /^[A-Z]{1}-\d{7}$/, + [PassportCountryCode.DEU]: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/, + [PassportCountryCode.FRA]: /^[0-9]{2}[A-Z]{2}[0-9]{5}$/, + [PassportCountryCode.CHN]: /^[EG]\d{8}$/, + [PassportCountryCode.JPN]: /^[A-Z]{2}\d{7}$/, + [PassportCountryCode.RUS]: /^\d{9}$/, + [PassportCountryCode.BRA]: /^[A-Z]{2}\d{6}$/, + [PassportCountryCode.ITA]: /^[A-Z0-9]{9}$/, + [PassportCountryCode.MEX]: /^\d{9}$/, + [PassportCountryCode.ZAF]: /^[A-Z0-9]{9}$/, + [PassportCountryCode.KOR]: /^[A-Z]{1}\d{8}$/, + [PassportCountryCode.SGP]: /^[A-Z]{1}\d{7}[A-Z]$/, + [PassportCountryCode.NLD]: /^[A-Z]{1}[0-9]{8}$/, + [PassportCountryCode.ESP]: /^[A-Z]{3}[0-9]{6}$/, + [PassportCountryCode.ARG]: /^[A-Z]{3}[0-9]{6}$/, + [PassportCountryCode.TUR]: /^[A-Z]{2}[0-9]{7}$/, + [PassportCountryCode.SAU]: /^[A-Z]{1}[0-9]{8}$/, + [PassportCountryCode.UAE]: /^\d{9}$/, + [PassportCountryCode.SWE]: /^[A-Z0-9]{8,9}$/, + [PassportCountryCode.CHE]: /^[A-Z0-9]{8}$/, + [PassportCountryCode.BEL]: /^[A-Z]{2}[0-9]{6}$/, + }; + + const regex = passportRegexes[countryCode]; + return regex.test(passportNumber); +}; diff --git a/src/postal-zip.ts b/src/postal-zip.ts deleted file mode 100644 index fe0c5e3..0000000 --- a/src/postal-zip.ts +++ /dev/null @@ -1,74 +0,0 @@ -// Define the CountryCode enum -export enum CountryCode { - US = 'US', // United States - CN = 'CN', // China - IN = 'IN', // India - ID = 'ID', // Indonesia - PK = 'PK', // Pakistan - BR = 'BR', // Brazil - NG = 'NG', // Nigeria - BD = 'BD', // Bangladesh - RU = 'RU', // Russia - MX = 'MX', // Mexico - JP = 'JP', // Japan - ET = 'ET', // Ethiopia - PH = 'PH', // Philippines - EG = 'EG', // Egypt - VN = 'VN', // Vietnam - CD = 'CD', // Democratic Republic of the Congo - TR = 'TR', // Turkey - IR = 'IR', // Iran - DE = 'DE', // Germany - TH = 'TH', // Thailand - GB = 'GB', // United Kingdom - FR = 'FR', // France - IT = 'IT', // Italy - TZ = 'TZ', // Tanzania - ZA = 'ZA', // South Africa -} - -/** - * Validates a postal code based on the country code. - * @param postalCode - The postal code to validate. - * @param countryCode - The country code as an enum. - * @returns True if the postal code is valid for the given country, otherwise false. - */ -export const isValid_Postal_Code = ( - postalCode: string, - countryCode: CountryCode -): boolean => { - const fiveDigitRegex = /^\d{5}$/; - const sixDigitRegex = /^\d{6}$/; - const fourDigitRegex = /^\d{4}$/; - - const postalCodeRegexes: { [key in CountryCode]: RegExp } = { - [CountryCode.US]: /^\d{5}(-\d{4})?$/, - [CountryCode.CN]: sixDigitRegex, - [CountryCode.IN]: sixDigitRegex, - [CountryCode.ID]: fiveDigitRegex, - [CountryCode.PK]: fiveDigitRegex, - [CountryCode.BR]: /^\d{5}-\d{3}$/, - [CountryCode.NG]: sixDigitRegex, - [CountryCode.BD]: fourDigitRegex, - [CountryCode.RU]: sixDigitRegex, - [CountryCode.MX]: fiveDigitRegex, - [CountryCode.JP]: /^\d{3}-\d{4}$/, - [CountryCode.ET]: fourDigitRegex, - [CountryCode.PH]: fourDigitRegex, - [CountryCode.EG]: fiveDigitRegex, - [CountryCode.VN]: sixDigitRegex, - [CountryCode.CD]: fiveDigitRegex, - [CountryCode.TR]: fiveDigitRegex, - [CountryCode.IR]: /^\d{10}$/, - [CountryCode.DE]: fiveDigitRegex, - [CountryCode.TH]: fiveDigitRegex, - [CountryCode.GB]: /^[A-Za-z]{1,2}\d[A-Za-z\d]? \d[A-Za-z]{2}$/, - [CountryCode.FR]: fiveDigitRegex, - [CountryCode.IT]: fiveDigitRegex, - [CountryCode.TZ]: fiveDigitRegex, - [CountryCode.ZA]: fourDigitRegex, - }; - - const regex = postalCodeRegexes[countryCode]; - return regex ? regex.test(postalCode) : false; -}; diff --git a/src/postal.ts b/src/postal.ts new file mode 100644 index 0000000..11d1a55 --- /dev/null +++ b/src/postal.ts @@ -0,0 +1,74 @@ +// Define the PostalCountryCode enum +export enum PostalCountryCode { + US = 'US', // United States + CN = 'CN', // China + IN = 'IN', // India + ID = 'ID', // Indonesia + PK = 'PK', // Pakistan + BR = 'BR', // Brazil + NG = 'NG', // Nigeria + BD = 'BD', // Bangladesh + RU = 'RU', // Russia + MX = 'MX', // Mexico + JP = 'JP', // Japan + ET = 'ET', // Ethiopia + PH = 'PH', // Philippines + EG = 'EG', // Egypt + VN = 'VN', // Vietnam + CD = 'CD', // Democratic Republic of the Congo + TR = 'TR', // Turkey + IR = 'IR', // Iran + DE = 'DE', // Germany + TH = 'TH', // Thailand + GB = 'GB', // United Kingdom + FR = 'FR', // France + IT = 'IT', // Italy + TZ = 'TZ', // Tanzania + ZA = 'ZA', // South Africa +} + +/** + * Validates a postal code based on the country code. + * @param postalCode - The postal code to validate. + * @param countryCode - The country code as an enum. + * @returns True if the postal code is valid for the given country, otherwise false. + */ +export const isValid_Postal_Code = ( + postalCode: string, + countryCode: PostalCountryCode +): boolean => { + const fiveDigitRegex = /^\d{5}$/; + const sixDigitRegex = /^\d{6}$/; + const fourDigitRegex = /^\d{4}$/; + + const postalCodeRegexes: { [key in PostalCountryCode]: RegExp } = { + [PostalCountryCode.US]: /^\d{5}(-\d{4})?$/, + [PostalCountryCode.CN]: sixDigitRegex, + [PostalCountryCode.IN]: sixDigitRegex, + [PostalCountryCode.ID]: fiveDigitRegex, + [PostalCountryCode.PK]: fiveDigitRegex, + [PostalCountryCode.BR]: /^\d{5}-\d{3}$/, + [PostalCountryCode.NG]: sixDigitRegex, + [PostalCountryCode.BD]: fourDigitRegex, + [PostalCountryCode.RU]: sixDigitRegex, + [PostalCountryCode.MX]: fiveDigitRegex, + [PostalCountryCode.JP]: /^\d{3}-\d{4}$/, + [PostalCountryCode.ET]: fourDigitRegex, + [PostalCountryCode.PH]: fourDigitRegex, + [PostalCountryCode.EG]: fiveDigitRegex, + [PostalCountryCode.VN]: sixDigitRegex, + [PostalCountryCode.CD]: fiveDigitRegex, + [PostalCountryCode.TR]: fiveDigitRegex, + [PostalCountryCode.IR]: /^\d{10}$/, + [PostalCountryCode.DE]: fiveDigitRegex, + [PostalCountryCode.TH]: fiveDigitRegex, + [PostalCountryCode.GB]: /^[A-Za-z]{1,2}\d[A-Za-z\d]? \d[A-Za-z]{2}$/, + [PostalCountryCode.FR]: fiveDigitRegex, + [PostalCountryCode.IT]: fiveDigitRegex, + [PostalCountryCode.TZ]: fiveDigitRegex, + [PostalCountryCode.ZA]: fourDigitRegex, + }; + + const regex = postalCodeRegexes[countryCode]; + return regex ? regex.test(postalCode) : false; +}; diff --git a/src/sin.ts b/src/sin.ts new file mode 100644 index 0000000..4242bc0 --- /dev/null +++ b/src/sin.ts @@ -0,0 +1,19 @@ +/** + * Social Insurance Number (Canada) Validation + * @param sin + * @returns + */ +export const isValid_SIN = (sin: string): boolean => { + const sanitized = sin.replace(/\s|-/g, ''); + if (!/^\d{9}$/.test(sanitized)) return false; + + const digits = sanitized.split('').map(Number); + const checkDigit = digits.pop(); + + const sum = digits + .map((d, i) => (i % 2 === 0 ? d : d * 2)) + .map((d) => (d > 9 ? d - 9 : d)) + .reduce((a, b) => a + b, 0); + + return (10 - (sum % 10)) % 10 === checkDigit; +}; diff --git a/src/tin.ts b/src/tin.ts new file mode 100644 index 0000000..98e61e2 --- /dev/null +++ b/src/tin.ts @@ -0,0 +1,67 @@ +export enum ICountryCode { + USA = 'USA', + CAN = 'CAN', + GBR = 'GBR', + AUS = 'AUS', + IND = 'IND', + DEU = 'DEU', + FRA = 'FRA', + CHN = 'CHN', + JPN = 'JPN', + RUS = 'RUS', + BRA = 'BRA', + ITA = 'ITA', + MEX = 'MEX', + ZAF = 'ZAF', + SGP = 'SGP', + NLD = 'NLD', + ESP = 'ESP', + ARG = 'ARG', + TUR = 'TUR', + SAU = 'SAU', + UAE = 'UAE', + SWE = 'SWE', + CHE = 'CHE', + BEL = 'BEL', +} + +/** + * TIN Validation + * @param identifier + * @param countryCode + * @returns + */ +export const isValid_TIN = ( + identifier: string, + countryCode: ICountryCode +): boolean => { + const tinEINRegexes: { [key in ICountryCode]: RegExp } = { + [ICountryCode.USA]: /^\d{2}-\d{7}$/, // EIN (e.g., 12-3456789) + [ICountryCode.CAN]: /^\d{9}$/, // SIN + [ICountryCode.GBR]: /^\d{9}$/, // NI + [ICountryCode.AUS]: /^\d{9}$/, // TFN + [ICountryCode.IND]: /^[A-Z]{5}\d{4}[A-Z]{1}$/, // PAN + [ICountryCode.DEU]: /^\d{11}$/, // Germany TIN + [ICountryCode.FRA]: /^\d{13}$/, // France TIN + [ICountryCode.CHN]: /^\d{15}$/, // China TIN + [ICountryCode.JPN]: /^\d{12}$/, // Japan TIN + [ICountryCode.RUS]: /^\d{10}$/, // Russia INN + [ICountryCode.BRA]: /^\d{11}$/, // Brazil CPF + [ICountryCode.ITA]: /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/, // Codice Fiscale + [ICountryCode.MEX]: /^[A-Z]{4}\d{6}[A-Z0-9]{3}$/, // RFC + [ICountryCode.ZAF]: /^\d{10}$/, // South Africa TIN + [ICountryCode.SGP]: /^\d{8}[A-Z]$/, // Singapore TIN + [ICountryCode.NLD]: /^\d{9}$/, // Netherlands TIN + [ICountryCode.ESP]: /^[A-Z]\d{8}$/, // Spain TIN + [ICountryCode.ARG]: /^\d{11}$/, // Argentina CUIT + [ICountryCode.TUR]: /^\d{10}$/, // Turkey TIN + [ICountryCode.SAU]: /^\d{10}$/, // Saudi Arabia TIN + [ICountryCode.UAE]: /^\d{15}$/, // UAE TIN + [ICountryCode.SWE]: /^\d{10}$/, // Sweden TIN + [ICountryCode.CHE]: /^\d{9}$/, // Switzerland TIN + [ICountryCode.BEL]: /^\d{11}$/, // Belgium TIN + }; + + const regex = tinEINRegexes[countryCode]; + return regex.test(identifier); +};