Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
How to fix: ReferenceError: validateEmail is not defined

I'm trying to make Register using EJS. Therefore, I'm checking

  1. If all input fields have values or not
  2. Is Email valid or not
  3. Password Length has to be < 6 characters
  4. Is Email already register or not And give them a message if they do not comply with the above conditions. To Check all these conditions I have the following code inside the userCtrl.js file userCtrl.js
const Users = require("../models/userModel");

const userCtrl = {
  //! Register User
  register: async (req, res) => {
    try {
      const { name, email, password } = req.body;
      // Check If All fields are filled with values or not
      if (!name || !email || !password) {
        return res.status(400).json({ masg: "Please fill allfields." });
      }
      // Check If email is valid
      if (!validateEmail(email)) {
        return res.status(400).json({ masg: "Please enter valid email." });
      }
      //Check password length
      if (password.length < 6) {
        return res
          .status(400)
          .json({ masg: "Password must be atleast 6 characters long." });
      }
      const user = await Users.findOne({ email });
      // Check If email is already registered
      if (await Users.findOne({ email })) {
        return res.status(400).json({ masg: "User already exists." });
      }
      res.json({ msg: "User Registered Successfully!" });
    } catch (err) {
      console.log(err);
      return res.status(500).json({ msg: err.message });
    }
  },
};

//! Exporting User Controller
module.exports = userCtrl;

Here is user Module for refrance.

const mongoose = require("mongoose");
const { Schema } = mongoose;

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    required: [true, "Please enter your name"],
    trim: true,
  },
  email: {
    type: String,
    required: [true, "Please enter your email"],
    trim: true,
    unique: true,
  },
  password: {
    type: String,
    required: [true, "Please enter your password"],
    trim: true,
  },
  role: {
    type: Number,
    default: 0, // 0 for user, 1 for admin
  },
  avator: {
    type: String,
    default:
      "https://res.cloudinary.com/manix/image/upload/v1639722719/avator/istockphoto-1214428300-170667a_c4fsdt.jpg",
  },
});
//! Exporting User Modules
module.exports = mongoose.model("Users", userSchema);

But when I try to register users using Postman then I got this error. enter image description here

Please Help me to fix this issue.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The issue is probably happening here

if (!validateEmail(email))

Where is your validateEmail() function located?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!