import {InjectorInstance} from '../../app.module';
import {Injectable} from '@angular/core';
import {FormGroup} from '@angular/forms';

@Injectable()
export class FrameFunction {
  /****************************
   * 设置表单未未点击过
   * @param {FormGroup} form
   * @constructor
   */
  public static UntouchedForm(form: FormGroup) {
    for (const c in form.controls) {
      form.controls[c].markAsUntouched();
    };
  }

  /*************************
   * 验证表单
   * @param {FormGroup} form
   * @returns {boolean}
   */
  public static validForm(form: FormGroup): boolean {
    for (const c in form.controls) {
      form.controls[c].markAsTouched();
    };
    return form.valid;
  }

  /*************************
   * 验证身份证格式-简单验证
   */
  public static isIdCard(cid) {
  //校验身份证号格式和长度
    const regPsidno = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[X])$)$/
    if (!regPsidno.test(cid)) {
      return false
    }
    return true;
  }

}
