title: Angular custom validator null plus custom validation checks
body: <p>I want to check empty validation plus the credit card inputs check. </p>
  
  <p>For ex: I have 3 input fields name 'card number','expiry','cvv'. 
  What i want is by default it is optional but if user enters input in the one of the fields user should enter valid input in the all 3 fields. </p>
  
  <p>So validation is like either all input blank or all input must have value and if all have value it should check for the valid card input validation check(For card number and expiry check i am planning for 3rd Party npm module).</p>
  
  <p>I have start it with like this from the reference of other stack overflow posts: </p>
  
  <pre><code>this.myForm = new FormGroup({
        'name': new FormControl(),
        'birthYear': new FormControl(),
        'card': new FormGroup({
          'cardNumber': new FormControl(),
          'expiry': new FormControl(),
          'cvv': new FormControl('',[NoWhitespaceValidator]),
        },OneFilledOutValidator)
      });
  </code></pre>
  
  <p>//Validation file</p>
  
  <pre><code>import {FormControl, FormGroup, AbstractControl, ValidatorFn} from '@angular/forms';
  import {Observable} from 'rxjs/Observable';
  
  export const OneFilledOutValidator = (): ValidatorFn =&gt; {
  
    return (group: FormGroup): {[key: string]: boolean} =&gt; {
  
      const fields = [];
  
      for (const field in group.controls) {
  
        if (group.controls.hasOwnProperty(field)) {
          fields.push(group.get(field).value);
        }
      };
  
      const result = fields.filter(field =&gt; !!field);
  
      const valid = result.length !== 0;
      console.log(valid);
      return valid ? null : {
        oneFilledOut: true
      };
    };
  };
  
  export function NoWhitespaceValidator(): ValidatorFn {
  
    return (control: AbstractControl): { [key: string]: any } =&gt; {
  
      let isWhitespace = (control.value || '').trim().length === 0;
      let isValid = !isWhitespace;
      console.log(isValid);
      return isValid ? null : { 'whitespace': 'value is only whitespace' }
  
    };
  }
  </code></pre>
  
  <p>But none of the validator is working for me. </p>
  
  <p>Can anyone suggest the good starting point for this? How can I implement this? <br>
  After this normal validation I would also need to check the if card fields is really valid based on common card validation of card number, expiry etc so suggest accordingly. </p>