Add email validator
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54439 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
0e262ae362
commit
8b970e94b8
|
@ -0,0 +1,27 @@
|
|||
import {Email} from "./email";
|
||||
|
||||
export class Validator {
|
||||
|
||||
private static regex = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
|
||||
|
||||
public static hasValidEmails(data: any): boolean {
|
||||
for(let i = 0; i < data.length; i++) {
|
||||
if (!this.emailValidator(data[i])) {
|
||||
// TODO remove console message after final testing
|
||||
console.log("INVALID EMAIL");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// TODO remove console message after final testing
|
||||
console.log("ALL EMAILS ARE VALID");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static emailValidator(email: any): boolean {
|
||||
if (email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue