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   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-06-22 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 54 All time: 10,614 This week: 59Up
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: 37 packages by
Country: Taiwan Taiwan
Age: 31
All time rank: 21046 in Taiwan Taiwan
Week rank: 4 Up1 in Taiwan Taiwan Up
Innovation award
Innovation award
Nominee: 17x

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 (11)  
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 (11)  /  test  
File Role Description
  Plain text file ValidatorTest.php Class Class source

  Files folder image Files (11)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:54
This week:0
All time:10,614
This week:59Up