[PM-32628] Add email validation to email verified auth flow (#19198)

* add email validation

* implement robust email validation regex
This commit is contained in:
John Harrington 2026-02-27 09:01:41 -07:00 committed by GitHub
parent 41c49a4d66
commit bf9bd9dade
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -10,6 +10,7 @@
type="submit"
buttonType="primary"
[loading]="loading()"
[disabled]="!validateEmail()"
[block]="true"
>
<span>{{ "sendCode" | i18n }} </span>

View File

@ -67,4 +67,25 @@ export class SendAccessEmailComponent implements OnInit, OnDestroy {
this.otp.markAsPristine();
}
}
validateEmail(): boolean {
const value: string = this.email.value?.trim() ?? "";
if (!value || value.length > 254) {
return false;
}
// RFC 5321-compliant regex: validates local@domain.tld structure
const EMAIL_REGEX =
/^[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])?)*\.[a-zA-Z]{2,}$/;
const [local, ...rest] = value.split("@");
// Ensure exactly one "@" and local part ≤ 64 chars (RFC 5321)
if (rest.length !== 1 || local.length > 64) {
return false;
}
return EMAIL_REGEX.test(value);
}
}