sahih_validator library

A comprehensive Flutter validation library for emails, phone numbers, passwords, addresses, URLs, and custom fields with excellent form integration.

This library provides robust validation methods that return null for valid input or error messages for invalid input, making them perfect for Flutter form validation.

For detailed usage examples and documentation, see the README.md file.

Classes

AgeResult
Represents an exact age result in years, months, and days.
DateOfBirthValidator
A utility class for validating a date of birth and calculating exact age.
SahihLocalization
Manages localization for SahihValidator.
SahihMessages
Repository for localized validation error messages.
SahihValidator
A comprehensive validation library for Flutter applications.
UrlData
Parsed URL data containing protocol, host, domain, path, etc.
UrlValidationResult
Result of URL validation containing validity status, message, and parsed data.

Enums

PatternType
Predefined regex patterns for common validation types.
SahihLanguage
Supported languages for validation error messages.

Extensions

AddressValidationExtensions on String
Extensions for address validation checks.
PatternTypeExtension on PatternType
Extension providing validation methods for PatternType enum.

Constants

kIsWeb → const bool
Pure Dart way to detect web platform
weakPasswords → const List<String>
List of common weak passwords to reject.

Functions

calculateCharsetSize(String input) int
Calculates character set size for password entropy.
customValidate({required String value, String? title, bool trimWhitespace = true, bool isRequired = true, int? minLength, int? maxLength, String? pattern, PatternType? patternType, bool allowOnlyNumbers = false, bool allowOnlyLetters = false, String? emptyMessage, String? minLengthMessage, String? maxLengthMessage, String? invalidPatternMessage, String? invalidNumberMessage, String? invalidLettersMessage, String? customValidator(String value)?, List<String>? existingValues, String? alreadyExistsMessage, SahihLanguage? lang}) String?
Provides comprehensive custom validation with multiple configurable rules.
isValidUrlAsync<T>(String url, {bool allowRelative = false, List<String>? allowedSchemes, List<String>? allowedDomains, bool normalize = true, bool checkDomainExists = false, SahihLanguage? lang}) Future<T>
Validates URLs with format checking and domain restrictions. Returns String/bool/UrlValidationResult based on generic type T.
validateAddress({required String address, String? title = "Address", bool trimWhitespace = true, bool isRequired = true, int minLength = 10, int maxLength = 200, bool requireStreetNumber = false, bool requireStreetName = true, bool requireCity = false, bool requireCountry = false, bool allowSpecialChars = true, bool allowNumbers = true, bool allowLetters = true, List<String>? forbiddenWords, List<String>? requiredWords, List<String>? existingAddresses, String? emptyMessage, String? minLengthMessage, String? maxLengthMessage, String? missingStreetNumberMessage, String? missingStreetNameMessage, String? missingCityMessage, String? missingCountryMessage, String? invalidSpecialCharsMessage, String? invalidNumbersMessage, String? invalidLettersMessage, String? forbiddenWordsMessage, String? requiredWordsMessage, String? alreadyExistsMessage, SahihLanguage? lang}) String?
Validates address with component requirements and content filtering. Returns null if valid, error message if invalid.
validateEmail({required String email, String? emptyMessage, String? invalidFormatMessage, bool trimWhitespace = true, List<String>? existingEmails, String? alreadyExistsMessage, SahihLanguage? lang}) String?
Validates an email address format and checks for duplicates.
validateLoginPassword({required String password, String? emptyMessage, SahihLanguage? lang}) String?
Validates a password for login purposes by checking if it's not empty.
validatePasswordParts({required String input, List<String>? commonPasswords, SahihLanguage? lang}) String?
Validates password strength with comprehensive security requirements.
validatePhone({required String phone, String? emptyMessage, String? invalidFormatMessage, bool trimWhitespace = true, List<String>? existingPhones, String? alreadyExistsMessage, SahihLanguage? lang}) String?
Validates phone number format (10-15 digits, optional +). Returns null if valid, error message if invalid.