-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
editor: add email validator #499
Conversation
Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
7a79afe
to
765a325
Compare
field.validators.email = { | ||
expression: (control: AbstractControl) => !control.value | ||
? true : (new RegExp(emailPattern)).test(control.value), | ||
message: `This value is not a valid email.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translation seems missing.
|
||
export function emailValidator(field: FormlyFieldConfig) { | ||
// Regex pattern to check email | ||
const emailPattern = /^([A-Za-z0-9\._%+-]+@[A-Za-z0-9\.-]+\.[A-Z|a-z]{2,})$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment to explain what is supported and what is not would be great.
import { AbstractControl } from '@angular/forms'; | ||
import { FormlyFieldConfig } from '@ngx-formly/core'; | ||
|
||
export function emailValidator(field: FormlyFieldConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be a good idea to write some tests.
Co-Authored-by: Bertrand Zuchuat bertrand.zuchuat@rero.ch
Why are you opening this PR?
How to test?
Code review check list