Skip to content

Commit 8b076aa

Browse files
MathildeJollymjolly
andauthored
feat(regex): add regex for password (#2533)
Co-authored-by: mjolly <[email protected]>
1 parent 1f9ed94 commit 8b076aa

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

.changeset/famous-foxes-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/regex": patch
3+
---
4+
5+
feat(regex): add regex for password

packages/regex/src/__tests__/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
ipv6Cidr,
4141
macAddress,
4242
nineDigitsCode,
43+
password,
4344
pathSegment,
4445
phone,
4546
reverseDNS,
@@ -1117,4 +1118,16 @@ describe('@regex', () => {
11171118
expect(sgPortRange.test(string)).toBe(expected)
11181119
})
11191120
})
1121+
1122+
describe('password', () => {
1123+
test.each([
1124+
['password', true],
1125+
['Password123!', true],
1126+
['Password123!@#', true],
1127+
['password`', false],
1128+
['Password`123!@#', false],
1129+
])('should match regex %s to be %s', (string, expected) => {
1130+
expect(password.test(string)).toBe(expected)
1131+
})
1132+
})
11201133
})

packages/regex/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ export const absolutePath = /^\/(([\w. -]*)[^\s?]\/?)+$/
9292
// A port range between 1 to 65535 separated by an hypen or a single number
9393
export const sgPortRange =
9494
/^(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5]?[0-9]{1,4})(-(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5]?[0-9]{1,4}))?$/
95+
96+
// Include all characters except backtick `
97+
export const password = /^[^`]+$/

0 commit comments

Comments
 (0)