RegexModel class
One rule shown by RegexUI: a title and a check (a RegExp or a function).
Constructors
- RegexModel({required String title, RegExp? regExp, bool test(String value)?, IconData? iconTrue, IconData? iconFalse, Color? colorTrue, Color? colorFalse, Color? textColorTrue, Color? textColorFalse, TextStyle? textStyle})
-
Creates a rule from a
regExpor atestfunction. -
RegexModel.allowOnly(List<
RegexChar> chars, {String allow = '', String? title}) -
Only the character groups in
chars, plus the characters inallow:RegexModel.allowOnly([RegexChar.letters, RegexChar.whitespace]).factory - RegexModel.contains(String text, {bool ignoreCase = true, String? title})
-
Contains
textsomewhere.factory - RegexModel.digit({int count = 1, String? title})
-
Contains
countor more digits.factory -
RegexModel.digitsOnly({List<
RegexChar> allowList = const [], String allow = '', String? title}) -
Only digits 0–9, plus
allowListgroups andallowcharacters.factory - RegexModel.email({String? title})
-
Looks like an e-mail address.
factory
- RegexModel.endsWith(String text, {bool ignoreCase = true, String? title})
-
Ends with
text, e.g.endsWith('@company.com').factory - RegexModel.exactLength(int length, {String? title})
-
Exactly
lengthcharacters, e.g. a 6-digit code.factory - RegexModel.iban({String? country, String? title})
-
A valid IBAN: country length and check digits (mod 97). Spaces and
lowercase are fine, as people paste "TR33 0006 1005 …". Pass
country(e.g. 'TR') to accept only that country.factory - RegexModel.lengthBetween(int min, int max, {String? title})
-
Between
minandmaxcharacters, e.g. a user name of 3–20.factory -
RegexModel.lettersAndDigits({List<
RegexChar> allowList = const [], String allow = '', String? title}) -
Only letters and digits, plus
allowListgroups andallowcharacters:RegexModel.lettersAndDigits(allowList: [RegexChar.underscore]).factory -
RegexModel.lettersOnly({List<
RegexChar> allowList = const [], String allow = '', String? title}) -
Only letters (any language), plus
allowListgroups andallowcharacters:RegexModel.lettersOnly(allowList: [RegexChar.whitespace]).factory - RegexModel.lowercase({int count = 1, String? title})
-
Contains
countor more lowercase letters (any language).factory - RegexModel.maxLength(int length, {String? title})
-
At most
lengthcharacters.factory - RegexModel.minLength(int length, {String? title})
-
At least
lengthcharacters.factory - RegexModel.noRepeating({int count = 3, String? title})
-
No character
countor more times in a row ("aaa" for 3).factory - RegexModel.noSpaces({String? title})
-
Contains no whitespace.
factory
-
RegexModel.notAllowed(List<
RegexChar> chars, {String allow = '', String? title}) -
None of the character groups in
charsand none of the characters inallow:RegexModel.notAllowed([RegexChar.whitespace, RegexChar.dot]).factory - RegexModel.notContains(String text(), {String? title})
-
Does not contain any word of
text(3+ letters), ignoring case and accents: with the name "Ali-Can Yılmaz", "yilmaz123" fails.RegexModel.notContains(() => fullName.text).factory - RegexModel.notStartsWith(String text, {String? title})
-
Does not start with
text, e.g.notStartsWith('0')for an ID number.factory - RegexModel.phone({String? title})
-
Looks like a phone number: optional +, 7–15 digits, spaces, dashes,
dots or parentheses.
factory
- RegexModel.sameAs(TextEditingController other, {String? title})
-
Equals the text of
other, e.g. "repeat password".factory - RegexModel.special({int count = 1, String? title})
-
Contains
countor more characters that are not a letter, digit or space.factory - RegexModel.startsWith(String text, {bool ignoreCase = false, String? title})
-
Starts with
text, e.g.startsWith('TR')for an IBAN.factory - RegexModel.uppercase({int count = 1, String? title})
-
Contains
countor more uppercase letters (any language).factory - RegexModel.url({String? title})
-
An http or https address with a domain, e.g. https://monsware.com.
factory
Properties
- colorFalse → Color?
-
Badge color when the rule is met / not met.
final
- colorTrue → Color?
-
Badge color when the rule is met / not met.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- iconFalse → IconData?
-
Icon when the rule is met / not met. Overrides the
RegexUIdefaults.final - iconTrue → IconData?
-
Icon when the rule is met / not met. Overrides the
RegexUIdefaults.final - regExp → RegExp?
-
Pattern the input must match. Either this or test is required.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- test → bool Function(String value)?
-
Custom check, used instead of regExp.
final
- textColorFalse → Color?
-
Text color when the rule is met / not met.
final
- textColorTrue → Color?
-
Text color when the rule is met / not met.
final
- textStyle → TextStyle?
-
Text style of title.
final
- title → String
-
Text shown next to the check mark, e.g. "At least 8 characters".
final
Methods
-
matches(
String value) → bool -
Whether
valuemeets this rule. Empty input never does, so nothing is ticked before the user types (e.g.^\w*\$ormaxLength). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
allMet(
List< RegexModel> rules, String value, {bool optional = false}) → bool -
Whether
valuemeets every rule; empty is valid only whenoptional. -
emailRules(
) → List< RegexModel> - Ready e-mail rules.
-
passwordRules(
{int minLength = 8}) → List< RegexModel> - Ready password rules: length, upper, lower, number, special character.
-
userNameRules(
{int minLength = 3, int maxLength = 20}) → List< RegexModel> -
Ready user name rules: 3–20 letters, numbers or
_, no spaces. -
validator(
List< RegexModel> rules, {bool optional = false}) → String? Function(String?) -
A
TextFormField.validatorthat returns the first unmet rule's title, soForm.validate()checks the same rules as the checklist. Empty is "Required", or fine whenoptional.