ConvoyPanel/resources/scripts/util/validation.ts
2023-04-09 20:11:02 +00:00

15 lines
479 B
TypeScript

import { t } from 'i18next'
import { z } from 'zod'
export const hostname = () =>
z
.string()
.regex(
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/,
{
message: t('errors.invalid_string.hostname', {
ns: 'zod',
validation: t('hostname', { ns: 'strings' }).toLowerCase(),
})!,
}
)