Skip to content

Prashles2/Validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Read Me

This is your basic, every day validation class.

Usage

Instantiate the class. The rule() method takes three required parameters; the value, the name (for error outputting) and the rules, respectively. It will also take an optional fourth parameter; set this to true if you want to validate an input statically.

Each call to the rule() method will return true/false for a successful or failed validation, respectively. Use the errors() method to get the errors for all the inputs. The method will return an array of error.

You can use the ruleA() method to pass rules as an array.

The errors() method takes a parameter for your file with the errors in. By default, it's the english file that comes with the class.

If a field is empty, it will NOT be validated unless the required validation rule is set.

You'll find sample usage in the validate.php file.

Validation Rules

required - Value cannot be empty
min_length[x] - Minimum length should be x or greater
max_length[x] - Maximum length should be x or less
ip - Valid IP address
match[x] - Value should match x
match_exact[x] - Value should match x exactly
match_password[x] - Same as the above, but doesn't show x- good for password confirmation fields
alphanum - String should be alphanumeric
numeric - Value should be numeric
min[x] - Value (number) should be at least x
max[x] - Value (number) should not be greater than x
url - Value should be a valid URL
match_regex[x] - x should be a valid REGEX pattern the value will be validated against

Extras

You can change the error messages in 'classes/validate/errors.english.php'. Pretty self-explanatory. You can also make your own file, just follow the format.

If you call the reset() method, the errors will be reset so you do not have in re-instantiate the class for validate another form.

To-do

Add error handling for validation rules that have parameters
Add more validation rules

About

Easy to use PHP validation class for validating inputs. Default error messages included.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages