1.0.2 • Published 5 years ago

easy-input-validator v1.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

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
<script src="your/path/to/easy-validator.min.js"></script>

Usage

You must simply add the validation name to the class of the input you want to validate.

Custom Validations

Custom Validation Demo

<script>
    EasyValidator.add("validate-selection", "That is impossible.", function(val) {
        return val !== "Other";
    })
</script>

You can create custom validations by using the easy-validator api.

API

EasyValidator MethodParameters
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

ValidationValidatesMessage
requiredAny field.This field is required.
validate-numberFloat only fields.Please enter a valid number.
validate-digitsInteger only fields.Please use numbers only in this field. Avoid spaces or other characters such as dots or commas.
validate-currency-dollarDollar only fields.Please enter a valid $ amount. For example $100.00.
validate-urlUrl only fields.Please enter a valid URL.
validate-emailEmail only fields.Please enter a valid email address. For example test@example.com.
validate-dateDate only fields.Please use this date format: dd/mm/yyyy. For example 17-03-2006 for the 17th of March, 2006.
validate-alphanumAlphanumeric fields.Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.
validate-alphaLetters only field.Please use letters only (a-z) in this field.

Demo

Click here for a live demo.

Demo gif

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago