Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/modern-brooms-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/regex": minor
---

feat: add webhosting username email regex
20 changes: 20 additions & 0 deletions packages/regex/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
uppercaseBasicSubdomain,
url,
uuid,
webhostingUsernameEmailRegex,
} from '..'

const alphanumDashDotsText = 'testwithdashdots-.'
Expand Down Expand Up @@ -1167,6 +1168,25 @@ describe('@regex', () => {
})
})

describe('webhostingUsernameEmailRegex', () => {
test.each([
['test', true],
['test_test', true],
['test-test', true],
['test.test', true],
['test.test.', false],
['test..test', false],
['test-test-', false],
['test_test_', false],
['test.test.', false],
['test..test', false],
['test..test', false],
['test..test', false],
])('should match regex %s to be %s', (string, expected) => {
expect(webhostingUsernameEmailRegex.test(string)).toBe(expected)
})
})

describe('uuid', () => {
test.each([
[asciiLetters, false],
Expand Down
4 changes: 4 additions & 0 deletions packages/regex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ export const password = /^(?!@)[^`]*$/
// A kafka username contains lowercase letters and numbers, with each segment starting and ending with a letter or number. Hyphens are only allowed in the middle of segments. Example: "username", "user-name", "my-group.user-name"
export const kafkaUsernameRegex =
/^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/

// The username cannot begin or end with a period, cannot contain two consecutive periods, and can only contain letters, numbers, periods, hyphens, and underscores. Example: "test", "test_test", "test-test"
export const webhostingUsernameEmailRegex =
/^(?!.*\.\.)[a-zA-Z0-9_-][a-zA-Z0-9._-]*[a-zA-Z0-9_-]$/
Loading