( path: SchemaPath<string, SchemaPathRules.Supported, TPathKind>, config?: BaseValidatorConfig<string, TPathKind>, )
| 59 | * @publicApi 22.0 |
| 60 | */ |
| 61 | export function email<TPathKind extends PathKind = PathKind.Root>( |
| 62 | path: SchemaPath<string, SchemaPathRules.Supported, TPathKind>, |
| 63 | config?: BaseValidatorConfig<string, TPathKind>, |
| 64 | ) { |
| 65 | validate(path, (ctx) => { |
| 66 | if (config?.when && !config.when(ctx)) { |
| 67 | return undefined; |
| 68 | } |
| 69 | if (isEmpty(ctx.value())) { |
| 70 | return undefined; |
| 71 | } |
| 72 | if (!EMAIL_REGEXP.test(ctx.value())) { |
| 73 | if (config?.error) { |
| 74 | return getOption(config.error, ctx); |
| 75 | } else { |
| 76 | return emailError({message: getOption(config?.message, ctx)}); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return undefined; |
| 81 | }); |
| 82 | } |
no test coverage detected
searching dependent graphs…