UNPKG

type-r2

Version:

Serializable, validated, and observable data layer for modern JS applications

11 lines (7 loc) 534 B
import { AttributeCheck, type } from 'type-r'; const emailPattern = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i; export function isEmail( x : string ) { return !x || !!x.match( emailPattern ); } (isEmail as AttributeCheck).error = 'Not valid email'; export const Email = type( String ).check( isEmail );