Skip to content

Commit

Permalink
Improve rgba validation
Browse files Browse the repository at this point in the history
  • Loading branch information
al-soup committed Nov 17, 2022
1 parent c1308b7 commit b851c1c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:

Expand All @@ -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
```
2 changes: 1 addition & 1 deletion validation/src/isRgbaString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""));
};

0 comments on commit b851c1c

Please sign in to comment.