diff --git a/packages/playground/src/components/smtp_server.vue b/packages/playground/src/components/smtp_server.vue index 0ec0f099a8..3896d48cd4 100644 --- a/packages/playground/src/components/smtp_server.vue +++ b/packages/playground/src/components/smtp_server.vue @@ -26,8 +26,8 @@ (v: string) => { return ( validators.isEmail('Please provide a valid email address.')(v) && - (validators.IsAlphaExpectDashAndUnderscore( - 'Username should consist of letters, dashs and underscores only.' + (validators.IsAlphanumericExpectDashAndUnderscore( + 'Username should consist of letters, numbers, dashs and underscores only.' )(v)) ); }, diff --git a/packages/playground/src/utils/validators.ts b/packages/playground/src/utils/validators.ts index cce255c217..fa9c86db60 100644 --- a/packages/playground/src/utils/validators.ts +++ b/packages/playground/src/utils/validators.ts @@ -125,7 +125,7 @@ export function IsAlphanumericExpectUnderscore(msg: string) { * @returns {(value: string) => { message: string, requiredTrue: boolean }} - A function that takes a string value as input and returns an object with an error message and a requiredTrue flag if the validation fails. */ -export function IsAlphaExpectDashAndUnderscore(msg: string) { +export function IsAlphanumericExpectDashAndUnderscore(msg: string) { return (value: string) => { if (!/^[a-zA-Z0-9_-]+$/.test(value)) { return { message: msg, requiredTrue: true }; diff --git a/packages/playground/tests/utils/validators/IsAlphaExpectDashAndUnderscore.test.ts b/packages/playground/tests/utils/validators/IsAlphaExpectDashAndUnderscore.test.ts index 765efc6b88..01d98227fe 100644 --- a/packages/playground/tests/utils/validators/IsAlphaExpectDashAndUnderscore.test.ts +++ b/packages/playground/tests/utils/validators/IsAlphaExpectDashAndUnderscore.test.ts @@ -1,14 +1,16 @@ import { describe, expect, it } from "vitest"; -import { IsAlphaExpectDashAndUnderscore } from "../../../src/utils/validators"; +import { IsAlphanumericExpectDashAndUnderscore } from "../../../src/utils/validators"; -const validator = IsAlphaExpectDashAndUnderscore("Username should consist of letters, dashs and underscores only."); +const validator = IsAlphanumericExpectDashAndUnderscore( + "Username should consist of letters, numbers, dashs and underscores only.", +); -describe("IsAlphaExpectDashAndUnderscore", () => { +describe("IsAlphanumericExpectDashAndUnderscore", () => { it("returns an error message for input with spaces", () => { const result = validator("hello world!"); expect(result).toEqual({ - message: "Username should consist of letters, dashs and underscores only.", + message: "Username should consist of letters, numbers, dashs and underscores only.", requiredTrue: true, }); }); @@ -16,7 +18,7 @@ describe("IsAlphaExpectDashAndUnderscore", () => { it("returns an error message for input with special characters", () => { const result = validator("hello@world"); expect(result).toEqual({ - message: "Username should consist of letters, dashs and underscores only.", + message: "Username should consist of letters, numbers, dashs and underscores only.", requiredTrue: true, }); });