Skip to content

Commit e3561b6

Browse files
author
Tom Lienard
authored
feat(regex): add alphanumdashunderscore regex (#1393)
1 parent 494c6cd commit e3561b6

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/regex': minor
3+
---
4+
5+
Add alphanumdashunderscore regex

packages/regex/src/__tests__/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
alphanumdashdotsspaces,
1818
alphanumdashorempty,
1919
alphanumdashspaces,
20+
alphanumdashunderscore,
2021
alphanumdashunderscoredotsspacesparenthesis,
2122
alphanumdots,
2223
ascii,
@@ -286,6 +287,28 @@ describe('@regex', () => {
286287
})
287288
})
288289

290+
describe('alphanumdashunderscore', () => {
291+
test.each([
292+
[alphanumdashText, true],
293+
[alphanumdashdotsText, false],
294+
[alphanumdashunderscoredotsparenthesisText, false],
295+
[asciiLetters, true],
296+
[asciiLowercase, true],
297+
[asciiUppercase, true],
298+
[digitsTest, true],
299+
[emailTest, false],
300+
[octdigits, true],
301+
[hexdigits, true],
302+
[printable, false],
303+
[punctuation, false],
304+
[whitespace, false],
305+
[cronTest, false],
306+
[macAddress1, false],
307+
])('should match regex %s to be %s', (string, expected) => {
308+
expect(alphanumdashunderscore.test(string)).toBe(expected)
309+
})
310+
})
311+
289312
describe('alphanumdashorempty', () => {
290313
test.each([
291314
[alphanumdashText, true],

packages/regex/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const alphanumdash = /^[a-zA-Z0-9-]*$/
77
export const alphanumdashdots = /^[a-zA-Z0-9-.]*$/
88
export const alphanumdashdotsorempty = /^$|^[a-zA-Z0-9-.]*$/
99
export const alphanumdashdotsspaces = /^[a-zA-Z0-9-.\s]*$/
10+
export const alphanumdashunderscore = /^[a-zA-Z0-9-_]*$/
1011
export const alphanumdashunderscoredotsspacesparenthesis =
1112
/^[a-zA-Z0-9-_.()\s]*$/
1213

0 commit comments

Comments
 (0)