File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 176
176
177
177
return getResult ( null ) ;
178
178
} ;
179
+ pub . uuid = function ( val ) {
180
+ if ( ! revalidator . validate . formats [ 'uuid' ] . test ( val ) ) {
181
+ return getResult ( getError ( 'format' , 'uuid' , val ) ) ;
182
+ }
183
+
184
+ return getResult ( null ) ;
185
+ } ;
179
186
pub . numberFloat = function ( val ) {
180
187
if ( typeof val !== 'string' || ! revalidator . validate . formats [ 'number-float' ] . test ( val ) ) {
181
188
return getResult ( getError ( 'format' , 'float' , val ) ) ;
Original file line number Diff line number Diff line change 232
232
}
233
233
} ,
234
234
'mongo-id' : / ^ [ 0 - 9 a - f A - F ] { 8 } [ 0 - 9 a - f A - F ] { 6 } [ 0 - 9 a - f A - F ] { 4 } [ 0 - 9 a - f A - F ] { 6 } $ / ,
235
+ 'uuid' : / ^ [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 12 } $ / i,
235
236
'number-float' : / ^ [ \- \+ ] ? \b ( \d + [ . ] \d + $ ) $ / ,
236
237
'float' : / ^ [ \- \+ ] ? \b ( \d + [ . ] \d + $ ) $ / ,
237
238
'integer' : / ^ [ \- \+ ] ? [ 0 - 9 ] + $ / ,
Original file line number Diff line number Diff line change @@ -149,6 +149,21 @@ describe('Formats', function () {
149
149
expect ( res3 . errors . length ) . toBe ( 1 ) ;
150
150
} ) ;
151
151
152
+ it ( 'should validate an UUID correctly' , function ( ) {
153
+ var res1 = val . formats . uuid ( '6648ae51-28f1-ad83-6b8d-f45284d2c173' ) ;
154
+ var res2 = val . formats . uuid ( 'b5f41c10-a0ef-886a-c5d2-91c32a360f4e' ) ;
155
+ var res3 = val . formats . uuid ( 'wayne' ) ;
156
+
157
+ expect ( res1 . valid ) . toBe ( true ) ;
158
+ expect ( res1 . errors . length ) . toBe ( 0 ) ;
159
+
160
+ expect ( res2 . valid ) . toBe ( true ) ;
161
+ expect ( res2 . errors . length ) . toBe ( 0 ) ;
162
+
163
+ expect ( res3 . valid ) . toBe ( false ) ;
164
+ expect ( res3 . errors . length ) . toBe ( 1 ) ;
165
+ } ) ;
166
+
152
167
it ( 'should validate a float number correctly' , function ( ) {
153
168
var res1 = val . formats . numberFloat ( 2.66 ) ;
154
169
var res2 = val . formats . numberFloat ( 3 ) ;
You can’t perform that action at this time.
0 commit comments