2023-03-29 17:56:42 +02:00
|
|
|
import { Validator } from "../Validator"
|
2024-07-16 12:49:17 +02:00
|
|
|
import { Translation } from "../../i18n/Translation"
|
|
|
|
|
import Translations from "../../i18n/Translations"
|
2023-03-29 17:21:20 +02:00
|
|
|
|
|
|
|
|
export default class StringValidator extends Validator {
|
2024-07-16 12:49:17 +02:00
|
|
|
|
|
|
|
|
constructor(type?: string, doc?: string, inputmode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search", textArea?: boolean) {
|
|
|
|
|
super(type ?? "string",
|
|
|
|
|
doc ?? "A simple piece of text which is at most 255 characters long",
|
|
|
|
|
inputmode,
|
|
|
|
|
textArea)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isValid(s: string): boolean {
|
|
|
|
|
return s.length <= 255
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFeedback(s: string, getCountry?: () => string): Translation | undefined {
|
|
|
|
|
if (s.length > 255) {
|
|
|
|
|
return Translations.t.validation.tooLong.Subs({ count: s.length })
|
|
|
|
|
}
|
|
|
|
|
return super.getFeedback(s, getCountry)
|
2023-03-29 17:21:20 +02:00
|
|
|
}
|
|
|
|
|
}
|