setWithRegex method

void setWithRegex(
  1. String? value, {
  2. String? regex,
  3. bool notify = true,
  4. bool forceNotify = false,
})

Sets given value only if regex matches.

regex - override of StringControl.regex -> one of them can't be 'null'.

Regex is typically used with StringControl.withRegex constructor and then setting value via setValue or value setter.

Implementation

void setWithRegex(String? value,
    {String? regex, bool notify = true, bool forceNotify = false}) {
  assert(regex != null || this.regex != null);

  regex ??= this.regex;

  if (RegExp(regex!).hasMatch(value ?? '')) {
    super.setValue(value, notify: notify, forceNotify: forceNotify);
  } else {
    printDebug('value [$value] has not match regex [$regex]');
  }
}