Describe the bug
isRgbColor rejects valid CSS rgba() colors where the alpha value has more than 2 decimal digits, or where alpha is 1.00 (a valid number equal to 1).
Examples
const validator = require('validator');
validator.isRgbColor('rgba(0,0,0,1.00)'); // false — expected true
validator.isRgbColor('rgba(0,0,0,0.123)'); // false — expected true
validator.isRgbColor('rgba(255,255,255,1.00)'); // false — expected true
validator.isRgbColor('rgba(0%,0%,0%,0.123)'); // false — expected true
// These DO work (2 or fewer decimal digits):
validator.isRgbColor('rgba(0,0,0,1.0)'); // true ✓
validator.isRgbColor('rgba(0,0,0,0.12)'); // true ✓
Root cause
In src/lib/isRgbColor.js, the alpha pattern is:
(0?\.\d\d?|1(\.0)?|0(\.0)?)
0?\.\d\d? matches at most 2 decimal places (.X or .XX)
1(\.0)? only matches 1 or 1.0, not 1.00, 1.000, etc.
0(\.0)? similarly only matches 0 or 0.0
The CSS specification defines <alpha-value> as a CSS <number>, which has no limit on decimal precision:
Expected fix
Extend the alpha pattern to allow any number of decimal digits and trailing zeros on boundary values 0 and 1:
(0?\.\d+|1(\.0+)?|0(\.0+)?)
Validator.js version: 13.15.35
Node.js version: 22+
OS platform: linux
Describe the bug
isRgbColorrejects valid CSSrgba()colors where the alpha value has more than 2 decimal digits, or where alpha is1.00(a valid number equal to 1).Examples
Root cause
In
src/lib/isRgbColor.js, the alpha pattern is:0?\.\d\d?matches at most 2 decimal places (.Xor.XX)1(\.0)?only matches1or1.0, not1.00,1.000, etc.0(\.0)?similarly only matches0or0.0The CSS specification defines
<alpha-value>as a CSS<number>, which has no limit on decimal precision:Expected fix
Extend the alpha pattern to allow any number of decimal digits and trailing zeros on boundary values
0and1:Validator.js version: 13.15.35
Node.js version: 22+
OS platform: linux