0

I want to validate the email address before update in mongodb. I'm a bit confused how to do that

var user = {
    name: req.body.name,
    email: req.body.email,
    password: req.body.password
};
db.users.insert(user, function(err, newuser) {
    if (err) return next(err);

    res.send({
        status: 'success',
        data: newuser,
    });
});
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
Ankit
  • 520
  • 7
  • 21

1 Answers1

-1

Please refer this link. Validate email address in JavaScript?

You can use HTML5 inbuilt feature:

HTML5 itself has email validation. If your browser supports HTML5 then you can use the following code.

<form><input type="email" placeholder="me@example.com">
    <input type="submit">
</form>

You can also use regular expressions for email validation

function validateEmail(email) {
    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
Community
  • 1
  • 1
Nidhin David
  • 2,426
  • 3
  • 31
  • 45