Skip to content

Commit

Permalink
Fix email validation (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeinAsylum authored Oct 20, 2023
1 parent ae02fc5 commit a9d0a50
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/app/utils/email/validate-email.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { isContainCardNumber } from 'checkout/utils/is-contain-card-number';
import * as cardValidator from 'card-validator';

/**
* 2 to 63 because domain name can be from 2 characters to 63 characters only by RFC 1035
*/
const EMAIL_REGEXP = /^[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,63}$/i;

const isContainCardNumber = (email: string) => {
const splitted = email.trim().split('@');
for (const numberOption of splitted) {
if (cardValidator.number(numberOption).isValid) {
return true;
}
}
return false;
};

export function validateEmail(value: string): boolean {
return !value || !value.trim() || !EMAIL_REGEXP.test(value.trim()) || isContainCardNumber(value);
}

0 comments on commit a9d0a50

Please sign in to comment.