@colisweb/rescript-toolkit 5.10.6 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/form/ReSchema.res
CHANGED
|
@@ -27,6 +27,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
27
27
|
module Validation = {
|
|
28
28
|
type rec t =
|
|
29
29
|
| Email({field: Lenses.field<string>, error: option<string>}): t
|
|
30
|
+
| Phone({field: Lenses.field<string>, error: option<string>}): t
|
|
30
31
|
| NoValidation({field: Lenses.field<'a>}): t
|
|
31
32
|
| StringNonEmpty({field: Lenses.field<string>, error: option<string>}): t
|
|
32
33
|
| StringRegExp({field: Lenses.field<string>, matches: string, error: option<string>}): t
|
|
@@ -81,6 +82,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
81
82
|
let false_ = (~error=?, field) => [False({field, error})]
|
|
82
83
|
|
|
83
84
|
let email = (~error=?, field) => [Email({field, error})]
|
|
85
|
+
let phone = (~error=?, field) => [Phone({field, error})]
|
|
84
86
|
|
|
85
87
|
let nonEmpty = (~error=?, field) => [StringNonEmpty({field, error})]
|
|
86
88
|
|
|
@@ -198,6 +200,22 @@ module Make = (Lenses: Lenses) => {
|
|
|
198
200
|
? Valid
|
|
199
201
|
: Error(error->Belt.Option.getWithDefault(i18n.email(~value))),
|
|
200
202
|
)
|
|
203
|
+
| Validation.Phone({field, error}) =>
|
|
204
|
+
let value = Lenses.get(values, field)
|
|
205
|
+
(
|
|
206
|
+
Field(field),
|
|
207
|
+
switch value {
|
|
208
|
+
| "" => Error(i18n.stringNonEmpty(~value=""))
|
|
209
|
+
| phone =>
|
|
210
|
+
if !(phone->Js.String2.startsWith("+33")) {
|
|
211
|
+
Error(error->Option.getWithDefault(i18n.phone))
|
|
212
|
+
} else if phone->Js.String2.sliceToEnd(~from=3)->Js.String2.length != 9 {
|
|
213
|
+
Error(error->Option.getWithDefault(i18n.phone))
|
|
214
|
+
} else {
|
|
215
|
+
Valid
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
)
|
|
201
219
|
| Validation.NoValidation({field}) => (Field(field), Valid)
|
|
202
220
|
| Validation.StringNonEmpty({field, error}) =>
|
|
203
221
|
let value = Lenses.get(values, field)
|
|
@@ -306,6 +324,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
306
324
|
| Validation.OptionNonEmpty({field}) => Field(field) == fieldName
|
|
307
325
|
| Validation.ArrayNonEmpty({field}) => Field(field) == fieldName
|
|
308
326
|
| Validation.CustomNestedSchema2({field}) => Field(field) == fieldName
|
|
327
|
+
| Validation.Phone({field}) => Field(field) == fieldName
|
|
309
328
|
}
|
|
310
329
|
)
|
|
311
330
|
|
|
@@ -313,6 +332,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
313
332
|
validators->Belt.Array.keep(validator =>
|
|
314
333
|
switch validator {
|
|
315
334
|
| Validation.False({field}) => Field(field) == fieldName
|
|
335
|
+
| Validation.Phone({field}) => Field(field) == fieldName
|
|
316
336
|
| Validation.True({field}) => Field(field) == fieldName
|
|
317
337
|
| Validation.IntMin({field}) => Field(field) == fieldName
|
|
318
338
|
| Validation.IntMax({field}) => Field(field) == fieldName
|
|
@@ -10,6 +10,7 @@ type t = {
|
|
|
10
10
|
stringRegExp: (~value: string, ~pattern: string) => string,
|
|
11
11
|
stringMin: (~value: string, ~min: int) => string,
|
|
12
12
|
stringMax: (~value: string, ~max: int) => string,
|
|
13
|
+
phone: string,
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
let default = {
|
|
@@ -31,4 +32,5 @@ let default = {
|
|
|
31
32
|
`Le champ doit avoir au minimum ${min->Int.toString} caractères.`,
|
|
32
33
|
stringMax: (~value as _value, ~max) =>
|
|
33
34
|
`Le champ doit avoir au maximum ${max->Int.toString} caractères.`,
|
|
35
|
+
phone: "Format du numéro invalide. Ex : +33612345678",
|
|
34
36
|
}
|
package/src/form/Reform.res
CHANGED
|
@@ -111,6 +111,7 @@ module Make = (Config: Config) => {
|
|
|
111
111
|
| Validation.FloatMin({field}) => (Field(field), Pristine)
|
|
112
112
|
| Validation.FloatMax({field}) => (Field(field), Pristine)
|
|
113
113
|
| Validation.Email({field}) => (Field(field), Pristine)
|
|
114
|
+
| Validation.Phone({field}) => (Field(field), Pristine)
|
|
114
115
|
| Validation.NoValidation({field}) => (Field(field), Pristine)
|
|
115
116
|
| Validation.StringNonEmpty({field}) => (Field(field), Pristine)
|
|
116
117
|
| Validation.StringRegExp({field}) => (Field(field), Pristine)
|
|
@@ -48,6 +48,15 @@ module Msg = {
|
|
|
48
48
|
}
|
|
49
49
|
let optionNonEmpty = {defaultMessage: "Champ requis"}
|
|
50
50
|
let invalidValue = {defaultMessage: "Valeur non valide."}
|
|
51
|
+
let passwordTooShort = {
|
|
52
|
+
defaultMessage: "Le mot de passe doit contenir au moins 10 caractères, avoir au moins 1 minuscule, 1 majuscule et un chiffre.",
|
|
53
|
+
}
|
|
54
|
+
let passwordCantBeEqualLogin = {
|
|
55
|
+
defaultMessage: "Veuillez ne pas utiliser votre idenfiant comme mot de passe",
|
|
56
|
+
}
|
|
57
|
+
let passwordCantContainLogin = {
|
|
58
|
+
defaultMessage: "Le mot de passe ne peut pas contenir l'identifiant.",
|
|
59
|
+
}
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
let toReSchemaResult = (opt: option<string>): ReSchema.fieldState<'a> =>
|
|
@@ -395,3 +404,14 @@ let required14Digits = (intl, value) => {
|
|
|
395
404
|
}
|
|
396
405
|
}
|
|
397
406
|
}
|
|
407
|
+
let password = (intl, ~login, value) => {
|
|
408
|
+
switch value {
|
|
409
|
+
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
410
|
+
| p if !Js.Re.test_(%re("/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}/"), p) =>
|
|
411
|
+
Some(intl->Intl.formatMessage(Msg.passwordTooShort))
|
|
412
|
+
| p if p === login => Some(intl->Intl.formatMessage(Msg.passwordCantBeEqualLogin))
|
|
413
|
+
| p if p->Js.String2.toLowerCase->Js.String2.includes(login->Js.String2.toLowerCase) =>
|
|
414
|
+
Some(intl->Intl.formatMessage(Msg.passwordCantContainLogin))
|
|
415
|
+
| _ => None
|
|
416
|
+
}
|
|
417
|
+
}
|