diff --git a/package-lock.json b/package-lock.json index e9aa790..7b2043a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1730,6 +1730,22 @@ } } }, + "@ngx-formly/core": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/@ngx-formly/core/-/core-5.5.1.tgz", + "integrity": "sha512-FmoDQNlwIEMj06D4iZCuV2Hk3kDAiDUsLyuIvWnn23z1Nk0GHcU/knhrYtodzJYwCPaGxiHAtHtxy5UlNOVOSg==", + "requires": { + "tslib": "^1.7.1" + } + }, + "@ngx-formly/material": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/@ngx-formly/material/-/material-5.5.1.tgz", + "integrity": "sha512-5ka27YDCkfFSdkoH4oSBib57QsOwib8j3T0Jt/4c76kGR3YkOjaKyNVg/MLyKvSo23EizOCOMGNDNu7fPEBPpQ==", + "requires": { + "tslib": "^1.9.0" + } + }, "@schematics/angular": { "version": "8.3.8", "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-8.3.8.tgz", diff --git a/package.json b/package.json index 6c700fe..9555e4c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "@angular/platform-browser": "^8.2.9", "@angular/platform-browser-dynamic": "^8.2.9", "@angular/router": "^8.2.9", + "@ngx-formly/core": "^5.5.1", + "@ngx-formly/material": "^5.5.1", "core-js": "^2.6.9", "hammerjs": "^2.0.8", "ng-inline-svg": "^9.1.0", diff --git a/src/app/formly.validator.ts b/src/app/formly.validator.ts new file mode 100644 index 0000000..8b63d7e --- /dev/null +++ b/src/app/formly.validator.ts @@ -0,0 +1,12 @@ +import { FormControl, ValidationErrors } from '@angular/forms'; +import {FormlyFieldConfig} from '@ngx-formly/core'; + +export const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + +export function EmailValidator(control: FormControl): ValidationErrors { + return EMAIL_REGEX.test(control.value) ? null : { 'email': true }; +} + +export function EmailValidatorMessage(err, field: FormlyFieldConfig) { + return `"${field.formControl.value}" is not a valid email address`; +}