(emails, render)
| 156 | |
| 157 | class EmailValidator { |
| 158 | validateEmails (emails, render) { |
| 159 | this.lastEmails = emails.join('\n') |
| 160 | // taken from http://www.regular-expressions.info/email.html |
| 161 | const emailRegex = /[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,63}/ |
| 162 | this.validEmails = ((() => { |
| 163 | const result = [] |
| 164 | for (const email of Array.from(emails)) { |
| 165 | if (emailRegex.test(email.trim().toLowerCase())) { |
| 166 | result.push(email) |
| 167 | } |
| 168 | } |
| 169 | return result |
| 170 | })()) |
| 171 | if (this.validEmails.length < emails.length) { return this.emailsInvalid(render) } |
| 172 | return this.emailsValid(render) |
| 173 | } |
| 174 | |
| 175 | emailString () { |
| 176 | if (!this.validEmails) { return } |
no test coverage detected