-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemailTest.js
25 lines (20 loc) · 1.12 KB
/
emailTest.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
if (typeof(module) !== 'undefined') {
var rhs = require('./rhs.js').rhs;
var automata = require('./automata.js').automata;
}
/* "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" */
var alphabetDigit = "a-zA-Z0-9"
var alphabetDigitscore = rhs.group(alphabetDigit, '-')
var symbols = "!#$%&'*+/=?^_`{|}~-";
var allowedChars = rhs.group(alphabetDigit, symbols).repeat(1, Infinity);
var dot = "(?:\\.)"
var dotCharRepeat = rhs.concat(dot, allowedChars).repeat(0, Infinity);
var local = rhs.concat(allowedChars, dotCharRepeat)
alphabetDigit = rhs.group(alphabetDigit)
var alphaDigRepeat = rhs.concat("(?:)", alphabetDigitscore.repeat(0, Infinity), alphabetDigit).repeat(0,1);
var domain = rhs.concat("(?:)", alphabetDigit, alphaDigRepeat.concat("\\.")).repeat(1, Infinity).concat(alphabetDigit).concat(alphaDigRepeat);
var email = local.concat('@', domain)
//can also write var email = rhs.concat(local, '@', domain);
console.log(email.toString())
console.log(email.match("radhika.marvin@yahoo.com"));
console.log(email.test("radhika.marvin@yahoo.com"));