How to validate email in angular 4 using formgroup or custom regexp?
Answer / Digvijay Bisht
To validate an email input field in Angular 4, you can use FormGroup and a custom validator function. First, define the FormGroup for your form:
```typescript
emailFormControl = new FormControl('', [Validators.required, this.validateEmail]);
```
Create a custom validateEmail function to check the email format using a regular expression:
```typescript
validateEmail(control: AbstractControl) {
const regex = new RegExp(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/);
return (regex.test(control.value)) ? null : {'invalidEmail': true};
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is bazel in angular 8?
What selector forces a style down through the child component tree into all the child component views?
Difference betweek javascript, jquery and angularjs?
What sre the directives in angularjs?
What is route guards?
What is ngmodel in angular?
What do double curly brackets are used in angular 5?
How to load select box during page initialization using AngularJS?
Explain the procss about angular project bootstrap?
What is difference between javascript and angular?
What is impure pipe?
List out the differences between config and run methods in angularjs?