1 |
|
2 |
|
3 |
|
4 | const bedrock = require('bedrock');
|
5 |
|
6 |
|
7 |
|
8 | const schema = {
|
9 | title: 'Email',
|
10 | description: 'An email address.',
|
11 | type: 'string',
|
12 | pattern: "^[-a-zA-Z0-9~!$%^&*_=+}{\\'?]+(\\.[-a-zA-Z0-9~!$%^&*_=+}{\\'?]+)*@(((([a-zA-Z0-9]{1}[a-zA-Z0-9\\-]{0,63}[a-zA-Z0-9]{1})|[a-zA-Z])\\.)+[a-zA-Z]{2,63})$",
|
13 | minLength: 1,
|
14 | maxLength: 100,
|
15 | errors: {
|
16 | invalid: 'The email address is invalid.',
|
17 | missing: 'Please enter an email address.'
|
18 | }
|
19 | };
|
20 |
|
21 | module.exports = function(extend, options) {
|
22 | if(options && options.lowerCaseOnly) {
|
23 | extend = extend || {};
|
24 | if(!('pattern' in extend)) {
|
25 | extend.pattern = "^[-a-z0-9~!$%^&*_=+}{\\'?]+(\\.[-a-z0-9~!$%^&*_=+}{\\'?]+)*@(((([a-z0-9]{1}[a-z0-9\\-]{0,63}[a-z0-9]{1})|[a-z])\\.)+[a-z]{2,63})$";
|
26 | }
|
27 | }
|
28 | if(extend) {
|
29 | return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
30 | }
|
31 | return schema;
|
32 | };
|