Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobsteves/easy-input-validator
A jQuery module that validates form fields.
https://github.com/jacobsteves/easy-input-validator
Last synced: about 1 month ago
JSON representation
A jQuery module that validates form fields.
- Host: GitHub
- URL: https://github.com/jacobsteves/easy-input-validator
- Owner: jacobsteves
- License: mit
- Created: 2018-04-20T00:54:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-16T00:30:13.000Z (over 5 years ago)
- Last Synced: 2024-04-24T20:26:35.615Z (9 months ago)
- Language: JavaScript
- Size: 406 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Easy Validator
A jQuery module that validates form fields. You can create your own validations with validator functions, or you can use the ones that are built in.## Prerequisities
- Jquery >= 1.11.1## Installation
### Package Manager
You can install via npm, yarn, bower, etc.
```
npm install easy-input-validator
```### Cloning the File
1. Clone this repository or simply download either `js/easy-validator.js` or `js/easy-validator.min.js`.
- Note: `easy-validator.min.js` is a minified version of `js/easy-validator.js`. This means that it is a smaller file. If you want to update the scripts contents, then copy `js/easy-validator.js`. Otherwise, download the minified version.
2. Include the file in your project
```html```
## Usage
You must simply add the validation name to the class of the input you want to validate.### Custom Validations
![Custom Validation Demo](demo/images/selectDemo.gif)```html
EasyValidator.add("validate-selection", "That is impossible.", function(val) {
return val !== "Other";
})```
You can create custom validations by using the easy-validator api.
#### API
| EasyValidator Method | Parameters |
|----------------------|------------|
| add(name, message, func) | name: The class name that the validation affects.
message: The message to be displayed if the input is invalid.
func: The validation function. Takes in one parameter - the value of the input. |
| addValidations(arr) | arr: Array of validations to be added to the validator. |
| getValidationMsg(val, name) | val: Input value to be validated.
name: Validation class name to be validating.
RETURNS: NULL - if the val is valid.
RETURNS: String - the validation message if val is invalid. |
| isValid(val, name) | val: Input value to be validated.
name: Validation class name to be validating.
RETURNS: Boolean - if the val is valid against the validation. |
| isEmpty(val) | val: Input value to be determined if empty.
RETURNS: Boolean - if the val is empty. |### Built-in Validations
| Validation | Validates | Message |
|----------------------|----------------------|--------------------|
| required | Any field. | This field is required. |
| validate-number | Float only fields. | Please enter a valid number. |
| validate-digits | Integer only fields. | Please use numbers only in this field. Avoid spaces or other characters such as dots or commas. |
| validate-currency-dollar | Dollar only fields. | Please enter a valid $ amount. For example $100.00. |
| validate-url | Url only fields. | Please enter a valid URL. |
| validate-email | Email only fields. | Please enter a valid email address. For example [email protected]. |
| validate-date | Date only fields. | Please use this date format: dd/mm/yyyy. For example 17-03-2006 for the 17th of March, 2006. |
| validate-alphanum | Alphanumeric fields. | Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.|
| validate-alpha | Letters only field. | Please use letters only (a-z) in this field. |## Demo
Click [here](http://jacobsteves.ca/software/easy-validator) for a live demo.![Demo gif](demo/images/signupPage.png)
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/jacobsteves/easy-validator/tags).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details