Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import { FormControl } from '@angular/forms';
  2.  
  3. export class UsernameValidator {
  4.  
  5. constructor() {
  6.  
  7. }
  8.  
  9.  
  10. validateEmail(email) {
  11. var re = new RegExp(/^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i);
  12. return re.test(email);
  13. }
  14.  
  15. validatePhone(phone) {
  16. var re = /^(([0-9]{3}) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$/;
  17. return re.test(phone);
  18. }
  19.  
  20. checkUsername(control){
  21.  
  22. if(this.validateEmail(control.value)||this.validatePhone(control.value))
  23. {
  24. return true;
  25. }
  26. else
  27. return false;
  28. }
  29.  
  30.  
  31.  
  32. }
  33.  
  34. import { Injectable } from '@angular/core';
  35. import 'rxjs/add/operator/map';
  36.  
  37. /*
  38. Generated class for the Validation provider.
  39.  
  40. See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  41. for more info on providers and Angular DI.
  42. */
  43. @Injectable()
  44. export class Validation {
  45.  
  46. constructor() {
  47. console.log('Hello Validation Provider');
  48. }
  49.  
  50. validateEmail(email) {
  51. return true;
  52. }
  53.  
  54. validatePhone(phone) {
  55. return true;
  56. }
  57.  
  58. checkUsername(control){
  59. console.log(control.value)
  60. var checkemail=this.validateEmail(control.value);
  61. var checkphone=this.validatePhone(control.value);
  62. if(checkemail||checkphone)
  63. return true;
  64. else
  65. return false;
  66. }
  67.  
  68. }
  69.  
  70. this.loginForm=formBuilder.group({
  71. username: ['',Validators.compose([Validators.required]),validation.checkUsername],
  72. password: ['',Validators.compose([Validators.required])]
  73. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement