UNPKG

1.05 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2012-2018 Digital Bazaar, Inc. All rights reserved.
3 */
4const bedrock = require('bedrock');
5
6// RFC 1034 - All labels have a max length of 63 octets.
7// https://tools.ietf.org/html/rfc1034#section-3.1
8const 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
21module.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};