Friday, 15 July 2011

hapijs - why is this joi regex validation for hex color failing -


Why should it be regex, but is it failing?

error

child "color" fails because "color" with value "" # 333acf "" does not match required pattern: / ^ # [A -FA-F 0-9] {6} $ /]

  Valid: {payload: {avatar: joi.object (). Key ({Color: Joy String (). Regex (/ ^ # [A-FA-F 0-9] {6} $ /), icon: joi.string () .min (2)})}} < / Code> 

payload

  {"avatar": {color: "# 333acf", icon: "b1"}}}  

Your color string should have an extra end space

  {"avatar" : {Color: "# 333acf", icon: "b1"}}  

Or your regex needs to allow strings, more than 6 characters by removing the end of the string anchor.

  / ^ # [A-Fa-f0- 9] {6} /  

No comments:

Post a Comment