Skip to content

Commit a921031

Browse files
committed
fix(max-length): use @ to differentiate bw lengths
1 parent 7fff32f commit a921031

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/app/utils/validation.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,23 @@ export const VALIDATION_USERNAME_OR_EMAIL = ({
243243
}: {
244244
isRequired?: boolean
245245
}) => ({
246-
format: (value) => {
246+
format: (value: string) => {
247247
if (!value) return true
248248
if (value.includes('@')) {
249249
return email.$validator(value, undefined, undefined)
250250
} else {
251251
return VALIDATION_FORMAT_SLUG(value)
252252
}
253253
},
254-
lengthMax: maxLength(
255-
Math.min(
256-
VALIDATION_USERNAME_LENGTH_MAXIMUM,
257-
VALIDATION_EMAIL_ADDRESS_LENGTH_MAXIMUM,
258-
),
259-
),
254+
lengthMax: {
255+
$validator: (value: string) => {
256+
if (!value) return true
257+
if (value.includes('@')) {
258+
return value.length <= VALIDATION_EMAIL_ADDRESS_LENGTH_MAXIMUM
259+
} else {
260+
return value.length <= VALIDATION_USERNAME_LENGTH_MAXIMUM
261+
}
262+
},
263+
},
260264
...(isRequired ? { required } : {}),
261265
})

0 commit comments

Comments
 (0)