x_validators library
A library that provides a collection of text validation utilities.
This library exports various modules for validating text, including email validation,
predefined validation rules, an abstract class for creating custom rules,
and a general-purpose xValidator function for performing validations.
Additionally, it exports language utilities from the core package.
Classes
- Contains
- checks if the input does contain the provided value;
- ContainsAny
- check if the value contain at lest one of String form the provided list
- EmailXValidator
- The EmailValidator entry point
- EndsWith
- Validates that the trimmed input ends with end.
- IsArabicChars
- Validates that the input contains only Arabic letters and whitespace.
- IsArabicNum
- Validates a positive integer in Latin digits, with no leading zero.
- IsBool
-
Validates that the input is a boolean literal —
trueorfalse. - IsDate
-
Validates that the input is a date string
DateTime.parsecan read. - IsDateAfter
- Validates that the input parses to a date strictly after date.
- IsDateMillis
-
checks if the input is a valid
dateto parse byDateTime.fromMillisecondsSinceEpochfactory - IsEgyptianPhone
- Validates that the input is an Egyptian mobile number (010/011/012/015 + 8 digits).
- IsEmail
-
checks if the input is a valid
emailaddress - IsEmpty
- Validates that the input is empty or whitespace-only.
- IsEnglishChars
- Validates that the input contains only English (A–Z) letters.
- IsFacebookUrl
- Validates that the input is a Facebook URL (facebook.com or fb.com).
- IsHexColor
- checks if the input is valid hex color
- IsHindiNum
- Validates a positive integer in Arabic-Indic digits, with no leading zero.
- IsIn
-
checks if the input
is inprovided List; - IsInstagramUrl
- Validates that the input is an Instagram URL (instagram.com).
- IsIpAddress
- Validates that the input is an IPv4 address (four dot-separated octets 0–255).
- ISKsaPhone
- Validates that the input is a Saudi (KSA) mobile number.
- IsLtrLanguage
- A validation rule that checks whether a language code is left-to-right (LTR).
- IsNotIn
-
checks if the input
is NOT inprovided List; - IsNumber
-
checks if the input is a valid
integer - IsNumbersOnly
- Validates that the input contains at least one digit.
- IsOptional
- allows you to skip the errors if the input is null
- IsPort
-
checks if the input is a valid
port - IsRequired
- Validates that the input is not empty after trimming.
- IsRTLLanguage
- A validation rule that checks whether a language code is right-to-left (RTL).
- IsSecureUrl
-
checks if the input is a secure
url - IsUrl
- Validates that the input is an http or https URL.
- IsYoutubeUrl
- Validates that the input is a YouTube URL (youtube.com).
- LanguageUtils
- Match
- checks if the input is match other string
- MaxLength
- checks if the input characters length is smaller than the max field
- MaxValue
- Validates that the parsed numeric input is less than or equal to max.
- MinLength
- checks if the input characters length is bigger than the min field
- MinValue
- Validates that the parsed numeric input is greater than or equal to min.
- NotContains
- checks if input does not contain the provided value;
- NotContainsAny
- check if the value does not contain any item from the provided list
- RegExpRule
- allow using a regular expression as validation rule
- StartsWith
- Validates that the trimmed input starts with pattern.
- TextXValidationRule
- An abstract class representing a text validation rule.
- XValidatorsLocalization
- A class responsible for localization of validation error messages.
Enums
- SubdomainType
- The Type enum
Functions
-
containsAny(
String v, List< String> list, {bool caseSensitive = false, bool trim = true}) → bool -
Returns
trueifvcontains any entry fromlist(case-insensitive by default). -
isArabicChars(
String input) → bool -
Returns
trueifinputconsists of Arabic letters and whitespace. -
isArabicNum(
String input) → bool -
Returns
trueifinputis a positive integer in Latin digits with no leading zero. -
isBool(
Object? input) → bool -
Returns
trueifinputis a bool, or the trimmed, case-insensitive string'true'or'false'. -
isDate(
String? v) → bool -
checks if the input is a valid
dateto parse by DartDateTimeclass -
isDateAfter(
Object? input, DateTime date) → bool -
Returns
trueifinput(aStringorDateTime) is strictly afterdate. -
isDateMills(
String v, {bool isUtc = false}) → bool -
checks if the input is a valid
dateto parse byDateTime.fromMillisecondsSinceEpochfactory -
isEgyptianNumber(
String str) → bool -
Returns
trueifstris a valid Egyptian mobile number. -
isEmail(
String? email) → bool - checks if the value can be well formatted email address
-
isEmpty(
String? input) → bool -
trimthe string then checks ifisEmptyif string is empty it will returns true -
isEnglishChars(
String input) → bool -
Returns
trueifinputconsists of English letters only. -
isFacebookUrlValid(
String url) → bool -
Returns
trueifurlis an http or https Facebook URL. -
isHexColor(
String? input) → bool -
can starts with or without
#must contains -
isHindiNum(
String input) → bool -
Returns
trueifinputis a positive integer in Arabic-Indic digits with no leading zero. -
isIn(
Object v, List< Object> list) → bool -
check if
stringis inList<String> -
isInstgramUrlValid(
String url) → bool -
Returns
trueifurlis an http or https Instagram URL. -
isIpAddress(
Object? input) → bool -
Returns
trueifinputis a string holding a dotted-quad IPv4 address. -
isKsaPhone(
String input) → bool -
Returns
trueifinputis a valid Saudi mobile number in a supported format. -
isNotEmpty(
String? string) → bool -
trimthe string then checks ifisNotEmpty -
isNotIn(
Object v, List< Object> list) → bool -
check if
valueisNOTinList -
isNumber(
String? input) → bool -
Returns
trueifinputparses as a number vianum.tryParse. -
isNumbersOnly(
String input) → bool -
Returns
trueifinputcontains at least one digit. -
isPort(
Object? input) → bool -
Returns
trueifinputis an integer port in the range 0–65535. -
isSecureUrl(
Object? input) → bool -
Returns
trueifinputis a string starting withhttps://(case-insensitive). -
isUrlValid(
String url) → bool -
Returns
trueifurlis a well-formed http or https URL. -
isYoutubeUrLValid(
String url) → bool -
Returns
trueifurlis an http or https YouTube URL. -
match(
Object? input, Object? other) → bool -
checks if two
Stringsare the same -
maxValue(
Object? value, num max) → bool -
Returns
trueifvalueparses to a number less than or equal tomax. -
minLength(
String? input, int min) → bool -
Returns
trueifinput, trimmed, is at leastmincharacters long. -
minValue(
Object? value, num min) → bool -
Returns
trueifvalueparses to a number greater than or equal tomin. -
notContainsAny(
String v, List< String> list) → bool -
Returns
trueifvcontains none of the entries inlist. -
xValidator(
List< TextXValidationRule> rules, {OnFailureCallBack? onFailureCallBack}) → String? Function(String?) -
A function that builds and returns a
String Function(String value)which triggers the provided validation rules.
Typedefs
-
OnFailureCallBack
= void Function(String? inputCallBack, List<
TextXValidationRule> rules, TextXValidationRule failedRule)