evalform
v1.0.10
Published
Evaluating Form Elements
Downloads
8
Maintainers
Readme
Evalform
Description
Evalform is a JavaScript module designed for validating various types of user input typically encountered in form submissions. It offers validation for email addresses, mobile numbers, names, passwords, and postal codes.
Installation
You can install the module via npm using the following command:
npm install evalform
Usage
To utilize the evalform
function, require it in your JavaScript file as follows:
const evalform = require('evalform');
You can then call the function with two arguments: the string to be validated and the type of validation to be performed.
const validation = evalform("[email protected]", "email");
console.log(validation.isValid); // true if valid, false otherwise
console.log(validation.error); // contains an error message if validation fails
The available types for validation are:
email
: Validates an email address format.mobile
: Validates a mobile number format (Indian format).name
: Validates a name format (alphabets, hyphens, and spaces).password
: Validates a password format (at least 8 characters including at least one uppercase letter, one lowercase letter, one number, and one special character).postal_code
: Validates a postal code format (Indian postal code format).
Example
const evalform = require('evalform');
const emailValidation = evalform("[email protected]", "email");
console.log(emailValidation.isValid); // true
const mobileValidation = evalform("1234567890", "mobile");
console.log(mobileValidation.isValid); // false
console.log(mobileValidation.error); // "Invalid mobile number"
License
This project is licensed under the MIT License.