mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-01 21:10:49 +08:00
[PM-32628] Add email validation to email verified auth flow (#19198)
* add email validation * implement robust email validation regex
This commit is contained in:
parent
41c49a4d66
commit
bf9bd9dade
@ -10,6 +10,7 @@
|
||||
type="submit"
|
||||
buttonType="primary"
|
||||
[loading]="loading()"
|
||||
[disabled]="!validateEmail()"
|
||||
[block]="true"
|
||||
>
|
||||
<span>{{ "sendCode" | i18n }} </span>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user