Kaynağa Gözat

:lock: Added regex for distance validation

tabs-content
tomit4 3 yıl önce
ebeveyn
işleme
029051938d

+ 10
- 6
frontend/src/entities/survey/survey.answer.validator.js Dosyayı Görüntüle

@@ -7,13 +7,16 @@ const answerValidator = {
7 7
         minDomainSegments: 2,
8 8
         tlds: { allow: domains },
9 9
     }),
10
-    // TODO: password validation is a moving target with regex, 
10
+    // TODO: password validation is a moving target with regex,
11 11
     // consider using a more robust library?
12 12
     password: Joi.string()
13 13
         .min(14)
14 14
         .max(30)
15 15
         .pattern(
16
-            new RegExp('^(?=.*[!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?])(?=.*[!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?])[a-zA-Z0-9!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?]{10,}$')),
16
+            new RegExp(
17
+                '^(?=.*[!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?])(?=.*[!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?])[a-zA-Z0-9!@#$%^&*()_+\\-=[\\]{};\':"\\\\|,.<>\\/?]{10,}$',
18
+            ),
19
+        ),
17 20
     // TODO: Change if going international (only works in usa)
18 21
     zipcode: Joi.string().min(5).max(5).pattern(new RegExp('^[0-9]{5}$')),
19 22
     seeking: Joi.string(),
@@ -23,10 +26,11 @@ const answerValidator = {
23 26
     pronouns: Joi.string(),
24 27
     language: Joi.string(),
25 28
     image: Joi.any(),
26
-    // TODO: specific distance units needed to be inputted within this field
27
-    // (i.e. km, mi, etc.) ... or just change the way the distance component
28
-    // works.
29
-    distance: Joi.string(),
29
+    // NOTE: Allows 1 to 3 digits and then distance metric
30
+    distance: Joi.string()
31
+        .min(4)
32
+        .max(15)
33
+        .pattern(new RegExp('^\\d{1,3}(\\.\\d{1,2})?\\s?(mi|km|mile|miles|kilometer|kilometers)$')),
30 34
     blurb: Joi.string().max(200),
31 35
     value: Joi.string(),
32 36
     aspect: Joi.number(),

Loading…
İptal
Kaydet