diff --git a/validation/README.md b/validation/README.md index 3cab25b..c9981c5 100644 --- a/validation/README.md +++ b/validation/README.md @@ -6,7 +6,7 @@ Library containing validator functions ### isRgbaString -Test if a given string is an RGBA value. You should lowercase the value and remove (or at least trim) all whitespace. +Test if a given string matches the pattern of an RGBA value. **Allowed formats**: @@ -16,6 +16,6 @@ Test if a given string is an RGBA value. You should lowercase the value and remo ```ts import { isRgbaString } from "@nzz/et-utils-validation"; -const rgba: String = "RGBA(255 ,255 , 0, 1.0) ".toLowerCase().replace(/ +/g, ''); +const rgba: String = "RGBA(255 ,255 , 0, 1.0) "; isRgbaString(rgba); // true ``` diff --git a/validation/src/isRgbaString.ts b/validation/src/isRgbaString.ts index 5e6c2a0..ed07c68 100644 --- a/validation/src/isRgbaString.ts +++ b/validation/src/isRgbaString.ts @@ -5,5 +5,5 @@ export const isRgbaString = (rgba: String): boolean => { const regex: RegExp = /rgba\(\s*(-?\d+|-?\d*\.\d+(?=%))(%?)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*.\d+)\s*\)/; - return regex.test(rgba); + return regex.test(rgba.toLowerCase().replace(/ +/g, "")); };