Skip to content

Commit 2c4d122

Browse files
authored
Merge pull request #2 from saicheck2233/issue#90_emailvalidation
issue#90: email validation does not work
2 parents 44f27b2 + f97020f commit 2c4d122

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/js/brutusin-json-forms.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ if (typeof brutusin === "undefined") {
7676
"exclusiveMaximum": "Value must be **lower than** `{0}`",
7777
"minProperties": "At least `{0}` properties are required",
7878
"maxProperties": "At most `{0}` properties are allowed",
79+
"email": "The email must at least consists an asterisk (@), following by a domain name with a dot (.)",
7980
"uniqueItems": "Array items must be unique",
8081
"addItem": "Add item",
8182
"true": "True",
@@ -277,6 +278,13 @@ if (typeof brutusin === "undefined") {
277278
return BrutusinForms.messages["maxLength"].format(s.maxLength);
278279
}
279280
}
281+
//Add a default regex pattern matching for email validation, or else user could use
282+
//the `pattern` field for their own custom regex pattern
283+
if (!s.pattern && s.format === "email") {
284+
if (!value.match(/[^@\s]+@[^@\s]+\.[^@\s]+/)) {
285+
return BrutusinForms.messages["email"];
286+
}
287+
}
280288
}
281289
if (value !== null && !isNaN(value)) {
282290
if (s.multipleOf && value % s.multipleOf !== 0) {

0 commit comments

Comments
 (0)