ValidatorFn pattern(String pattern)

Validator that requires a control to match a regex to its value.

Source

static ValidatorFn pattern(String pattern) {
  return /* Map < String , dynamic > */ (model_module
      .AbstractControl control) {
    if (Validators.required(control) != null) return null;
    var regex = new RegExp('''^${ pattern}\$''');
    String v = control.value;
    return regex.hasMatch(v)
        ? null
        : {
            "pattern": {
              "requiredPattern": '''^${ pattern}\$''',
              "actualValue": v
            }
          };
  };
}