Skip to main content

Overview

LocalRegex provides general-purpose validation methods for common data types used across applications. These validators work with standard formats and are not Zimbabwe-specific.

Email Validation

isEmail()

Validates email address format.
value
String
required
The email address to validate
Returns: bool - true if valid email format, false otherwise

Format Requirements

1

Local Part

Letters, numbers, and common special characters are allowed before the @ symbol
2

@ Symbol

Required separator between local and domain parts
3

Domain

Alphanumeric characters followed by dot
4

TLD

At least one top-level domain (can have multiple, e.g., .co.uk)

Code Examples

LocalRegex.isEmail('[email protected]');           // true
LocalRegex.isEmail('[email protected]');     // true
LocalRegex.isEmail('[email protected]');        // true
LocalRegex.isEmail('[email protected]');     // true
LocalRegex.isEmail('[email protected]'); // true

Password Validation

isPassword()

Validates password strength according to common security requirements.
password
String
required
The password to validate
Returns: bool - true if password meets requirements, false otherwise Pattern: ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?[!@#$&*~^%()+=|]).{8,}$

Password Requirements

Minimum Length

At least 8 characters long

Uppercase

At least 1 uppercase letter (A-Z)

Lowercase

At least 1 lowercase letter (a-z)

Number

At least 1 digit (0-9)

Special Character

At least 1 special character! @ # $ & * ~ ^ % ( ) + = |

Code Examples

LocalRegex.isPassword('Pass123!');          // true
LocalRegex.isPassword('MyP@ssw0rd');        // true
LocalRegex.isPassword('Secure#Pass123');    // true
LocalRegex.isPassword('C0mpl3x&Str0ng!');   // true
Security Note: While this validator enforces basic password requirements, consider additional checks like password history, common password lists, and user-specific patterns for production applications.

URL Validation

isUrl()

Validates HTTP and HTTPS URLs.
url
String
required
The URL to validate
Returns: bool - true if valid URL format, false otherwise Pattern: https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)

Format Requirements

1

Protocol

Must start with http:// or https://
2

Subdomain (Optional)

Can include www. or other subdomains
3

Domain

Alphanumeric domain name (1-256 characters)
4

TLD

Top-level domain (1-6 characters)
5

Path/Query (Optional)

Can include paths, query strings, and fragments

Code Examples

LocalRegex.isUrl('https://example.com');                    // true
LocalRegex.isUrl('http://www.example.com');                 // true
LocalRegex.isUrl('https://subdomain.example.co.uk');        // true
LocalRegex.isUrl('https://example.com/path/to/page');       // true
LocalRegex.isUrl('https://example.com?query=value&id=123'); // true
LocalRegex.isUrl('https://example.com/page#section');       // true

Date Validation

isDate()

Validates date format and checks for valid dates (including leap years).
date
String
required
The date string to validate
Returns: bool - true if valid date, false otherwise

Supported Formats

The validator accepts dates with various separators:
  • / (slash): 31/12/2024
  • - (hyphen): 31-12-2024
  • . (dot): 31.12.2024

Date Validation Rules

  • 31 days: Jan, Mar, May, Jul, Aug, Oct, Dec
  • 30 days: Apr, Jun, Sep, Nov
  • 29 days: Feb (leap years)
  • 28 days: Feb (non-leap years)

Code Examples

LocalRegex.isDate('31/12/2024');    // true
LocalRegex.isDate('29/02/2024');    // true (leap year)
LocalRegex.isDate('15-06-2023');    // true
LocalRegex.isDate('01.01.2000');    // true
LocalRegex.isDate('30/04/2024');    // true
The date validator expects day/month/year format (European/UK style), not month/day/year (US style).

IP Address Validation

isIpAddress()

Validates IPv4 address format.
ipAddress
String
required
The IP address to validate
Returns: bool - true if valid IPv4 address, false otherwise Pattern: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

IPv4 Format Requirements

1

Four Octets

Four numbers separated by dots
2

Octet Range

Each octet must be between 0 and 255
3

Valid Ranges

  • 0-9: Single digit
  • 10-99: Two digits
  • 100-199: Three digits (1xx)
  • 200-249: Three digits (2xx)
  • 250-255: Three digits (25x)

Code Examples

LocalRegex.isIpAddress('192.168.1.1');      // true
LocalRegex.isIpAddress('10.0.0.1');         // true
LocalRegex.isIpAddress('255.255.255.255');  // true
LocalRegex.isIpAddress('0.0.0.0');          // true
LocalRegex.isIpAddress('172.16.254.1');     // true
This validator only supports IPv4 addresses. IPv6 addresses are not currently supported.

Complete Example

import 'package:localregex/localregex.dart';

void validateUserInput({
  required String email,
  required String password,
  required String website,
  required String birthDate,
  required String ipAddress,
}) {
  // Validate email
  if (!LocalRegex.isEmail(email)) {
    print('Invalid email address');
    return;
  }
  
  // Validate password strength
  if (!LocalRegex.isPassword(password)) {
    print('Password must be at least 8 characters with uppercase, '
          'lowercase, number, and special character');
    return;
  }
  
  // Validate website URL
  if (!LocalRegex.isUrl(website)) {
    print('Invalid URL format');
    return;
  }
  
  // Validate birth date
  if (!LocalRegex.isDate(birthDate)) {
    print('Invalid date format (use DD/MM/YYYY)');
    return;
  }
  
  // Validate IP address
  if (!LocalRegex.isIpAddress(ipAddress)) {
    print('Invalid IPv4 address');
    return;
  }
  
  print('All validations passed!');
}

// Example usage
void main() {
  validateUserInput(
    email: '[email protected]',
    password: 'Secure123!',
    website: 'https://example.com',
    birthDate: '15/06/1990',
    ipAddress: '192.168.1.1',
  );
}

Validation Summary

Email

Method: isEmail()Format: [email protected]Validates standard email format

Password

Method: isPassword()Requirements: 8+ chars, upper, lower, digit, specialStrong password validation

URL

Method: isUrl()Format: https://example.comHTTP/HTTPS URLs only

Date

Method: isDate()Format: DD/MM/YYYYValidates real dates including leap years

IP Address

Method: isIpAddress()Format: 192.168.1.1IPv4 addresses (0-255 per octet)

Best Practices

Client-Side Only: These validators are for client-side validation. Always validate on the server side as well for security.
User Feedback: Provide clear error messages when validation fails, explaining what format is expected.
Password Storage: Never store passwords in plain text. Always use proper hashing algorithms (bcrypt, argon2, etc.) on the server side.

Password Generation

LocalRegex also provides a password generation utility:
// Generate a random password that meets validation requirements
final password = LocalRegex.generatePassword(length: 12);

print(password);  // e.g., "aB3!xY9@mN2#"

// Verify it passes validation
assert(LocalRegex.isPassword(password));
length
int
default:"12"
The desired password length (minimum 8 recommended)
The generated password will always include:
  • Lowercase letters
  • Uppercase letters
  • Numbers
  • Special characters
And will pass the isPassword() validation.

Build docs developers (and LLMs) love