aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-06-24 21:53:20 +0530
committerBobby <[email protected]>2022-06-24 21:53:20 +0530
commit555d44220b016978cd9cbddf8d1ac6bb84a1f142 (patch)
treee434151c4dea941f91652531d39262bdf6a82341 /functions
parent00e99b844c260e0263e5d5403d284ba07450005e (diff)
downloadthatcomputerscientist-555d44220b016978cd9cbddf8d1ac6bb84a1f142.tar.xz
thatcomputerscientist-555d44220b016978cd9cbddf8d1ac6bb84a1f142.zip
basic email validation on account page
Diffstat (limited to 'functions')
-rw-r--r--functions/validate.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/functions/validate.js b/functions/validate.js
index ecf90564..3e9ff111 100644
--- a/functions/validate.js
+++ b/functions/validate.js
@@ -15,6 +15,32 @@ function validateAuthorization(auth) {
}
}
+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])+$/;
+
+function 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;
+}
+
module.exports = {
validateAuthorization,
+ isEmailValid
};