Full commit for review
This commit is contained in:
31
api/modules/formatHandler.js
Normal file
31
api/modules/formatHandler.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const dns = require('dns');
|
||||
|
||||
function isEmailDomainValid(email) {
|
||||
const domain = email.split('@')[1];
|
||||
return new Promise((resolve, reject) => {
|
||||
dns.lookup(domain, (err, address) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
const isIPAddress = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(address);
|
||||
resolve(isIPAddress);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isValidEmail(email) {
|
||||
const emailRegex = /\S+@\S+\.\S+/;
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
function isNumber(x) {
|
||||
return /^-?[\d.]+(?:e-?\d+)?$/.test(x);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isEmailDomainValid,
|
||||
isValidEmail,
|
||||
isNumber,
|
||||
};
|
||||
Reference in New Issue
Block a user