validatorrr
A comprehensive and light weight validation library for common data validation tasks.
Installation
You can install validatorrr
via npm:
npm install validatorrr
Or include it via CDN:
<script src="https://cdn.jsdelivr.net/gh/mr-shade/validatorrr@latest/validatorrr.js"></script>
Usage
Here's an example of how you can use validatorrr
:
import v from 'validatorrr';
console.log(v.isEmail('test@example.com'));
console.log(v.isURL('https://www.example.com'));
console.log(v.isNotEmptyString('Hello'));
console.log(v.isPalindrome('A man, a plan, a canal, Panama'));
console.log(v.isPalindrome('IamnotPalindrome'));
console.log(v.isWithinRange(5, 1, 10));
console.log(v.isInArray('apple', ['banana', 'apple', 'orange']));
console.log(v.isUUID('123e4567-e89b-12d3-a456-426614174000'));
console.log(v.isHexColor('#ffcc00'));
console.log(v.isDateYYYYMMDD('2024-04-09'));
console.log(v.isCreditCard('4111-1111-1111-1111'));
console.log(v.isPhoneNumber('+1234567890'));
console.log(v.isPostalCode('12345'));
console.log(v.isStrongPassword('Nndw$%623!'));
console.log(v.isAlpha('abcdefghijklmnopqrstuvwxyz'));
console.log(v.isAlphanumeric('abc123'));
console.log(v.isNumeric('12345'));
Features
- isEmail(email): Checks if a string is a valid email address.
- isURL(url): Checks if a string is a valid URL.
- isNotEmptyString(str): Checks if a string is not empty.
- isPalindrome(str): Checks if a string is a palindrome.
- isWithinRange(num, min, max): Checks if a number is within a specified range.
- isInArray(value, array): Checks if a value exists in an array.
- isUUID(uuid): Checks if a string is a valid UUID.
- isHexColor(color): Checks if a string is a valid HEX color.
- isDateYYYYMMDD(dateString): Checks if a string is a valid date in the format
YYYY-MM-DD
. - isCreditCard(cardNumber): Checks if a string is a valid credit card number.
- isPhoneNumber(phone): Checks if a string is a valid phone number.
- isPostalCode(postalCode, countryCode): Checks if a string is a valid postal code.
- isStrongPassword(password): Checks if a string is a strong password.
- isAlpha(str): Checks if a string contains only alphabetic characters.
- isAlphanumeric(str): Checks if a string contains only alphanumeric characters.
- isNumeric(str): Checks if a string contains only numeric characters.
Usage via CDN
You can also use validatorrr
directly in the browser via CDN:
<script src="https://cdn.jsdelivr.net/npm/validatorrr"></script>
Documentation
isEmail(email)
Checks if a string is a valid email address.
Parameters:
email
: String - The email address to validate.
Example:
const isValidEmail = validatorrr.isEmail('test@example.com');
console.log(isValidEmail);
isURL(url)
Checks if a string is a valid URL.
Parameters:
url
: String - The URL to validate.
Example:
const isValidURL = validatorrr.isURL('https://www.example.com');
console.log(isValidURL);
isNotEmptyString(str)
Checks if a string is not empty.
Parameters:
str
: String - The string to check.
Example:
const isValid = validatorrr.isNotEmptyString('Hello');
console.log(isValid);
Issues
If you encounter any issues or have suggestions, please feel free to open an issue on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
https://dev.to/sh20raj/xvalidatorrr-a-lightweight-validation-library-for-javascript-2c59