UX: indicate that a search field is actually a regex, add feedback to the filterview

This commit is contained in:
Pieter Vander Vennet 2024-09-17 02:51:02 +02:00
parent 5da63bf83a
commit ebe7ff85f8
5 changed files with 39 additions and 7 deletions

View file

@ -0,0 +1,22 @@
import StringValidator from "./StringValidator"
import { s } from "vitest/dist/env-afee91f0"
import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
export default class RegexValidator extends StringValidator{
constructor() {
super("regex", "Validates a regex")
}
getFeedback(s: string): Translation | undefined {
try{
new RegExp(s)
}catch (e) {
return Translations.T("Not a valid Regex: "+e)
}
}
isValid(s: string): boolean {
return this.getFeedback(s) === undefined
}
}