Php Validation Class
This article includes the PHP class I use for simple form validation.
I originally wrote this article on October 10th 2009 while I was working with CodeIgniter. I have since moved on from CodeIgniter and maintain my own personal framework, but still include and have updated this class for 2021.
The idea of the class is to ease the ability to check and clean input from forms.
Remember, using JavaScript will cut down on your server load and is highly recommended but always have a server side backup.
If you have any suggestions or fixes please comment below, or make an issue in Github.
How To Use
Install the class with composer:
composer require nickyeoman/php-validation-class
If you have not done so already, Install Composer on Ubuntu
Include the file in your script
USE NickyeomanValidation;
$valid = new NickyeomanValidationValidate();
Call any of the functions like so, see documentation above each function
$valid = new Validate;
if ( $valid->isEmail($email) ) { /** do something **/ } else { /** create error **/ }
if ( $valid->isPhone($phone) ) { /** do something **/ } else { /** create error **/ }
if ( $valid->isPostalCode($postal) ) { /** do something **/ } else { /** create error **/ }
if ( $valid->isZipCode($zip) ) { /** do something **/ } else { /** create error **/ }
Comments
You need to login to comment.