mongoose-type-email
An email field-type for Mongoose schemas
usage
This will validate email, correctly:
var mongoose = ;; var UserSchema = email: work: mongooseSchemaTypesEmail home: mongooseSchemaTypesEmail ;
You can also use the stuff in String
type:
var UserSchema = email: work: type: mongooseSchemaTypesEmail required: true home: type: mongooseSchemaTypesEmail required: true ;
You can also use it as an array:
var UserSchema = emails: type: mongooseSchemaTypesEmail;
You can add 'allowBlank: true' in order to allow empty string ('') when the field is not required
var mongoose = ;; var UserSchema = email: work: type: mongooseSchemaTypesEmail allowBlank: true // allows '' as a value home: mongooseSchemaTypesEmail // throws when the value is '' ;
You can specify a default custom error message by overriding mongoose.SchemaTypes.Email.defaults.message
var mongoose = ;;mongooseSchemaTypesEmaildefaultsmessage = 'Email address is invalid' var UserSchema = email: work: mongooseSchemaTypesEmail home: mongooseSchemaTypesEmail ;
By default, this library follows the same validation you see in the html spec for type=email
which allows local email addresses, and other non-standard email types. If you want more complete TLD validation (eg user@host.com
) you can use the correctTld
options:
var UserSchema = email: work: type: mongooseSchemaTypesEmail correctTld: true home: type: mongooseSchemaTypesEmail correctTld: true ;