-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae02fc5
commit a9d0a50
Showing
1 changed file
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |