Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const allColors = cssContent

### Identifiers

- <span id="einre">__`einRE`__</span>: Matches a valid EIN number.
- <span id="ssnre">__`ssnRE`__</span>: Matches a valid SSN. Provides 3 matching groups, 1 (area number), 2 (group number), and 3 (serial number).
- <span id="uuidre">__`uuidRE`__</span>: Matches a UUID.

### JavaScript
Expand Down
11 changes: 11 additions & 0 deletions src/ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ import { lockdownRE } from './lib/lockdown-re'
export const uuidREString = '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}'
// Identifiers: Matches a UUID.
export const uuidRE = lockdownRE(uuidREString)

export const ssnREString = '(?!000|666|9\\d\\d)(\\d{3})-?(\\d\\d)-?(?!0000)(\\d{4})'
// Identifiers: Matches a valid SSN. Provides 3 matching groups, 1 (area number), 2 (group number), and 3 (serial number).
export const ssnRE = lockdownRE(ssnREString)

// https://www.irs.gov/businesses/small-businesses-self-employed/how-eins-are-assigned-and-valid-ein-prefixes
const validEINPrefix = [10, 12, 60, 67, 50, 53, 1, 2, 3, 4, 5, 6, 11, 13, 14, 16, 21, 22, 23, 25, 34, 51, 52, 54, 55, 56, 57, 58, 59, 65, 30, 32, 35, 36, 37, 38, 61, 15, 24, 40, 44, 94, 95, 80, 90, 33, 39, 41, 42, 43, 48, 62, 63, 64, 66, 68, 71, 72, 73, 74, 75, 76, 77, 82, 83, 84, 85, 86, 87, 88, 91, 92, 93, 98, 99, 20, 26, 27, 45, 46, 47, 81, 31].map((prefix) => ('' + prefix).padStart(2, '0'))

export const einREString = '(?:' + validEINPrefix.join('|') + ')-?\\d{7}'
// Identifiers: Matches a valid EIN number.
export const einRE = lockdownRE(einREString)
3 changes: 2 additions & 1 deletion src/test/data/rfc-2822-date-times.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const invalidRFC2822Times = [

export const validRFC2822Dates = [
'Mon, 7 Jan 1992 12:12',
'6 Jan 1992 12:12 UT'
'6 Jan 1992 12:12 UT',
'6 Jan 1992 12:13:14 UT'
]

export const invalidRFC2822Dates = [
Expand Down
24 changes: 22 additions & 2 deletions src/test/ids.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ limitations under the License.
import { groupTest, groupTestPartial } from './lib/test-lib'
import * as regex from '../ids'

const validUUID = ['00000000-0000-1000-8000-000000000000']
const invalidUUID = ['00000000-0000-0000-0000-000000000000']
const validUUID = [
'00000000-0000-1000-8000-000000000000',
'00000000-0000-1000-8000-000000abcdef',
'00000000-0000-1000-8000-000000ABCDEF'
]
const invalidUUID = [
'00000000-0000-0000-0000-000000000000',
'00000000-0000-0000-0000-00000000000G',
'00000000-0000-0000-0000-00000000000g'
]

groupTest(regex.uuidRE, validUUID, invalidUUID, 'uuidRE')
groupTestPartial(regex.uuidREString, validUUID, invalidUUID, 'uuidRE')

const validSSN = ['100-00-0001', '123-45-6789', '123-45-0001', '123456789']
const invalidSSN = ['000-45-6789', '666-45-6789', '900-45-6789', '123-45-0000', '123-45-678']

groupTest(regex.ssnRE, validSSN, invalidSSN, 'SSN')
groupTestPartial(regex.ssnREString, validSSN, invalidSSN, 'SSN')

const validEIN = ['01-3456789', '59-3456789', '123456789']
const invalidEIN = ['07-3456789', '49-3456789', '12-345678']

groupTest(regex.einRE, validEIN, invalidEIN, 'EIN')
groupTestPartial(regex.einREString, validEIN, invalidEIN, 'EIN')