Schemas: ValidateEmail
Validating an email type field.
🪶 The validateEmail option in MerlinDB is useful when you want to validate an email
.1 import MerlinDB, { Schema} from "@chrisaxxwell/merlin-db";2 //Or if you are using 'merlindb.max.js' just call 'new MerlinDB()'; 3 4 const merlin = new MerlinDB( ) ;5 merlin.connect( "MY-STORE-DATABASE") ; 6 7 const ClientSchema = Schema( { 8 email: { 9 type: String , 10 unique: true , 11 validateEmail: [ 12 true , 13 "Invalid email", 14 /[your-regex-to-validate-email]/g 15 ] 16 } , 17 } ) ; 18 19 var clientModel = merlin.model( "Users", ClientSchema) ;20 21 clientModel.insert( { 22 email: "lalala" 23 } ) .then( e => { 24 /* OK... */ 25 } ) .catch( e => { 26 console.log( e) ; 27 //returns Invalid email 28 } ) ;