Click here to Skip to main content
15,789,698 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my schema, how would I allow only specific email to register. For example, only people with an email address ending in can register

import mongoose from "mongoose";

const UserSchema = new mongoose.Schema(
		name: {
			type: String,
			required: true
		email: {
			type: String,
			required: [true, "Please enter your email"],
			unique: true,
		password: {
			type: String,
			required: true,
			minlength: 5,

	{ collection: 'user-data' }

export default mongoose.model('User', UserSchema)

What I have tried:

I have tried to use regex

Updated 10-Jan-23 0:24am

1 solution

Try simplifying your regex:
If you are going to use regular expressions, you need a helper tool. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900