Download the PHP package coderavine/sparta without Composer
On this page you can find all versions of the php package coderavine/sparta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coderavine/sparta
More information about coderavine/sparta
Files in coderavine/sparta
Package sparta
Short Description PHP Library for Effortless Input Validation
License MIT
Homepage https://github.com/coderavine/sparta
Informations about the package sparta
Introduction
Sparta is a simple, elegant, and easy to use stand-alone PHP library for effortless inputs validation. Sparta uses simple, straightforward validation techniques that attempt to take the pain out of development by easing common validation tasks used in the majority of web projects. If you are looking for implementing reliable, effective, quick validations and a library that can be extended easily to fit your needs, then Sparta is definitely for you.
Installation
You can install and update Sparta library using Composer:
Usage
Sparta validation can be used in two different ways. Below are various examples that explain both:
-
You can simply use a validator class to validate a certain type of data. For example, if you have a date and you want to ensure that only a date and nothing else is provided by end users, then you can do something as follows:
- Another alternative way is to use the Validation class that accepts the data to be validated along with a list of defined rules for each attributes and let it do the heavy lifting for you. A simple example that explains this is given below:
Let us assume that we have an account registration option in our web-based application and we want to enforce the below rules for the username field:
- It must be a
required
field - It must only contain
alphabetic
characters - It must have a
minimum
andmaximum
length of 12 and 50 respectively
To achieve this, we first need to define our validation rules for the username as follows:
After that, we need to ensure that the username field content is available in our user's input collection:
Then, we can simply run the validation by passing both data and rules to the Validation object to handle the validation for us as follows:
Documentation
Please refer to the Library Documentation for more information.
Contributions
Contributing your PHP love to Sparta is always more than welcome via a Pull Request. Please refer to Contribution Section
License
The Sparta Validation is open-sourced library licensed under the MIT license