-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailvalidate.js
40 lines (33 loc) · 964 Bytes
/
emailvalidate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var express = require("express");
var bodyparser = require("body-parser");
var app = express();
app.use(bodyparser.json());
app.post("/", (req, res) => {
let emailId = req.body.email;
if (isEmailValid(emailId)) {
res.send("Valid Email id");
} else {
res.send("Invalid Email id");
}
});
var emailRegex =
/^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
isEmailValid = (email) => {
if (!email) return false;
if (email.length > 254) return false;
var valid = emailRegex.test(email);
if (!valid) return false;
// Further checking of some things regex can't handle
var parts = email.split("@");
if (parts[0].length > 64) return false;
var domainParts = parts[1].split(".");
if (
domainParts.some(function (part) {
return part.length > 63;
})
)
return false;
return true;
};
app.listen(3000);
console.log("server started");