@@ -26,34 +26,12 @@ THE SOFTWARE.
2626
2727---------------------------------------------------------------------------*/
2828
29- import { IsIPv4Internal } from './ipv4.ts'
29+ const Email = / ^ (? ! . * \. \. ) [ a - z 0 - 9 ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + (?: \. [ a - z 0 - 9 ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + ) * @ [ a - z 0 - 9 ] (?: [ a - z 0 - 9 - ] { 0 , 61 } [ a - z 0 - 9 ] ) ? (?: \. [ a - z 0 - 9 ] (?: [ a - z 0 - 9 - ] { 0 , 61 } [ a - z 0 - 9 ] ) ? ) * $ / i
3030
3131/**
3232 * Returns true if the value is an Email
33- * @specification Json Schema 2020-12
33+ * @specification ajv-formats
3434 */
3535export function IsEmail ( value : string ) : boolean {
36- const dot = value . indexOf ( '.' )
37- const at = value . indexOf ( '@' )
38- const quoted = value [ 0 ] === '"' && value [ at - 1 ] === '"'
39- const ipLiteral = value [ at + 1 ] === '[' && value [ value . length - 1 ] === ']'
40- const ipv6 = ipLiteral && value . indexOf ( ':' , at ) !== - 1
41- const ipv4 = ipLiteral && ! ipv6 && IsIPv4Internal ( value , at + 2 , value . length - 1 )
42- return ( at > 0 && at < value . length - 1 ) &&
43- ! (
44- // .test@example .com
45- ( ! quoted && dot === 0 ) ||
46- // te..st@example .com
47- ( ! quoted && dot !== - 1 && value . indexOf ( '.' , dot + 1 ) === dot + 1 ) ||
48- // test.@example .com
49- ( dot !== - 1 && value . indexOf ( '@' , dot ) === dot + 1 ) ||
50- // joe bloggs@example .com
51- ( ! quoted && value . indexOf ( ' ' ) !== - 1 ) ||
52- // user1@oceania .org, user2@oceania.org
53- ( value . indexOf ( ',' ) !== - 1 ) ||
54- // joe.bloggs@[127.0.0.300]
55- ( ipLiteral && ! ipv4 && ! ipv6 ) ||
56- // joe.bloggs@invalid =domain.com
57- ( value . indexOf ( '=' , at ) !== - 1 )
58- )
36+ return Email . test ( value )
5937}
0 commit comments