Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { FormControl } from '@angular/forms';
- export class UsernameValidator {
- constructor() {
- }
- validateEmail(email) {
- var re = new RegExp(/^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i);
- return re.test(email);
- }
- validatePhone(phone) {
- var re = /^(([0-9]{3}) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$/;
- return re.test(phone);
- }
- checkUsername(control){
- if(this.validateEmail(control.value)||this.validatePhone(control.value))
- {
- return true;
- }
- else
- return false;
- }
- }
- import { Injectable } from '@angular/core';
- import 'rxjs/add/operator/map';
- /*
- Generated class for the Validation provider.
- See https://angular.io/docs/ts/latest/guide/dependency-injection.html
- for more info on providers and Angular DI.
- */
- @Injectable()
- export class Validation {
- constructor() {
- console.log('Hello Validation Provider');
- }
- validateEmail(email) {
- return true;
- }
- validatePhone(phone) {
- return true;
- }
- checkUsername(control){
- console.log(control.value)
- var checkemail=this.validateEmail(control.value);
- var checkphone=this.validatePhone(control.value);
- if(checkemail||checkphone)
- return true;
- else
- return false;
- }
- }
- this.loginForm=formBuilder.group({
- username: ['',Validators.compose([Validators.required]),validation.checkUsername],
- password: ['',Validators.compose([Validators.required])]
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement