Angular2 Custom Validator Typescript Example

In this example, we will be creating a Angular 2 custom validator that validates email format in Typescript.

 

Folder

Angular2 Custom Validator Typescript Example folder

email.validator.ts

This is the custom validator that we are creating.

app.component.ts

This is the main component with the custom validator injected.

app.component.tpl.html

This is the template of the main app.

boot.ts

index.html

Result

Angular2 Custom Validator Typescript Example demo invalid

Angular2 Custom Validator Typescript Example demo valid

Resource


facebooktwittergoogle_plusredditlinkedin

Wayne Hong

Passionate Java full stack developer.
  • SamuelSLF

    Hello! Thanks for the post.
    I can get the value of my return ?
    Example: {’emailValidation’:’email is invalid.’}
    Key = emailValidation
    Value = email is invalid.

    i can use this value in my HTML Code?