PHP Classes

How to Use a PHP Validation Library to Validate Strings that May Represent Different Types of Values Using the Package General Validator: Validate text strings of different types of values

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-06-22 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: 18 This week: 18All time: 11,260 This week: 2Up
Version License PHP version Categories
generalvalidator 1.0MIT/X Consortium ...5Validation, PHP 7
Description 

Author

This package can validate text strings of different types of values.

It provides a base validation class and several sub-classes specialized in validating different types of values passed as strings.

Currently, the classes can validate:

- Country codes

- Email addresses

- Length of strings

- Passwords

- URLs

Picture of Chun-Sheng, Li
  Performance   Level  
Name: Chun-Sheng, Li <contact>
Classes: 31 packages by
Country: Taiwan Taiwan
Innovation award
Innovation award
Nominee: 15x

Winner: 1x

Documentation

Synopsis

General string validation. Currently Email address, string length, password, url and country code validation. Easily extendable with others.

Code Example

$validator = PasswordValidator(3); // Minimum password score 3
if ($validator->validate("my-very-long-password-is-good")) {
	// Good, your password is strong enough
}

API Reference

Classes:

Validator() // Parent for all classes
EmailValidator()
UrlValidator()
CountryCodeValidator()
LengthValidator(int $minLength, int $maxLength)
PasswordValidator(int $minScore) // Score from 0 (weakest) to 4 (strongest)

Methods:

Validator::validate(string) // Pass in the test string and returns bool
Validator::load() // Shorthand class loader
Validator::getValue() // Returns the output of the validator, null if no output
Validator::getError() // Returns the error from the validator, null if no error
StringValidator::setMin(int) // Update the min string length
StringValidator::setMax(int) // Update the max string length
PasswordValidator::setMinScore(int) // Update the min password score required for a pass```

Tests

Tests are provided in test/ValidatorTest.php and can be run with PHPUnit

License

BSD 2-Clause License - See LICENSE


  Files folder image Files  
File Role Description
Files folder imagetest (1 file)
Files folder imageValidators (6 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  test  
File Role Description
  Plain text file ValidatorTest.php Class Class source

  Files folder image Files  /  Validators  
File Role Description
  Plain text file CountryCodeValidator.php Class Class source
  Plain text file EmailValidator.php Class Class source
  Plain text file LengthValidator.php Class Class source
  Plain text file PasswordValidator.php Class Class source
  Plain text file UrlValidator.php Class Class source
  Plain text file Validator.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:18
This week:18
All time:11,260
This week:2Up