2024-09-17 02:51:02 +02:00
|
|
|
import StringValidator from "./StringValidator"
|
|
|
|
|
import { s } from "vitest/dist/env-afee91f0"
|
|
|
|
|
import { Translation } from "../../i18n/Translation"
|
|
|
|
|
import Translations from "../../i18n/Translations"
|
|
|
|
|
|
2024-10-19 14:44:55 +02:00
|
|
|
export default class RegexValidator extends StringValidator {
|
2024-09-17 02:51:02 +02:00
|
|
|
constructor() {
|
|
|
|
|
super("regex", "Validates a regex")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFeedback(s: string): Translation | undefined {
|
2024-10-19 14:44:55 +02:00
|
|
|
try {
|
2024-09-17 02:51:02 +02:00
|
|
|
new RegExp(s)
|
2024-10-19 14:44:55 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
return Translations.T("Not a valid Regex: " + e)
|
2024-09-17 02:51:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isValid(s: string): boolean {
|
|
|
|
|
return this.getFeedback(s) === undefined
|
|
|
|
|
}
|
|
|
|
|
}
|