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.The email address to validate
bool - true if valid email format, false otherwise
Format Requirements
Code Examples
Password Validation
isPassword()
Validates password strength according to common security requirements.The password to validate
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
URL Validation
isUrl()
Validates HTTP and HTTPS URLs.The URL to validate
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
Code Examples
Date Validation
isDate()
Validates date format and checks for valid dates (including leap years).The date string to validate
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
- Day Ranges
- Leap Years
- Year Range
- 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
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.The IP address to validate
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
Code Examples
This validator only supports IPv4 addresses. IPv6 addresses are not currently supported.
Complete Example
Validation Summary
Password
Method:
isPassword()Requirements: 8+ chars, upper, lower, digit, specialStrong password validationURL
Method:
isUrl()Format: https://example.comHTTP/HTTPS URLs onlyDate
Method:
isDate()Format: DD/MM/YYYYValidates real dates including leap yearsIP 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 Generation
LocalRegex also provides a password generation utility:The desired password length (minimum 8 recommended)
- Lowercase letters
- Uppercase letters
- Numbers
- Special characters
isPassword() validation.