JS -- add function eMailValidate used to validate an email address

This commit is contained in:
Calixte Denizet 2020-12-10 15:38:31 +01:00
parent b194c820bf
commit f94269c0d1
3 changed files with 29 additions and 1 deletions

View file

@ -37,6 +37,14 @@ class AForm {
"m/d/yy HH:MM",
];
this._timeFormats = ["HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt"];
// The e-mail address regex below originates from:
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
this._emailRegex = new RegExp(
"^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+" +
"@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?" +
"(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
);
}
_parseDate(cFormat, cDate) {
@ -577,6 +585,10 @@ class AForm {
this.AFDate_KeystrokeEx(this._timeFormats[pdf]);
}
}
eMailValidate(str) {
return this._emailRegex.test(str);
}
}
export { AForm };