@@ -27,7 +27,10 @@ const internals = {
2727 }
2828 } ,
2929 dataUriRegex : / ^ d a t a : [ \w + . - ] + \/ [ \w + . - ] + ; ( ( c h a r s e t = [ \w - ] + | b a s e 6 4 ) , ) ? ( .* ) $ / ,
30- hexRegex : / ^ ( 0 x ) ? [ 0 - 9 a - f ] + $ / i,
30+ hexRegex : {
31+ withPrefix : / ^ ( 0 x ) ? [ 0 - 9 a - f ] + $ / i,
32+ withoutPrefix : / ^ [ 0 - 9 a - f ] + $ / i
33+ } ,
3134 ipRegex : Ip . regex ( { cidr : 'forbidden' } ) . regex ,
3235 isoDurationRegex : / ^ P (? ! $ ) ( \d + Y ) ? ( \d + M ) ? ( \d + W ) ? ( \d + D ) ? ( T (? = \d ) ( \d + H ) ? ( \d + M ) ? ( \d + S ) ? ) ? $ / ,
3336
@@ -368,16 +371,18 @@ module.exports = Any.extend({
368371 hex : {
369372 method ( options = { } ) {
370373
371- Common . assertOptions ( options , [ 'byteAligned' ] ) ;
374+ Common . assertOptions ( options , [ 'byteAligned' , 'withPrefix' ] ) ;
372375
373- options = { byteAligned : false , ...options } ;
376+ options = { byteAligned : false , withPrefix : false , ...options } ;
374377 Assert ( typeof options . byteAligned === 'boolean' , 'byteAligned must be boolean' ) ;
378+ Assert ( typeof options . withPrefix === 'boolean' , 'withPrefix must be boolean' ) ;
375379
376380 return this . $_addRule ( { name : 'hex' , args : { options } } ) ;
377381 } ,
378382 validate ( value , helpers , { options } ) {
379383
380- if ( ! internals . hexRegex . test ( value ) ) {
384+ const re = options . withPrefix ? internals . hexRegex . withPrefix : internals . hexRegex . withoutPrefix ;
385+ if ( ! re . test ( value ) ) {
381386 return helpers . error ( 'string.hex' ) ;
382387 }
383388
0 commit comments