Data Validation Library is a JavaScript package for validating common data types such as email, password, and date using regular expressions.
npm install data-validation-library
const DataValidation = require('data-validation-library');
// Example usage for email validation
const emailValidator = new DataValidation('example@email.com');
const isEmailValid = emailValidator.validateEmail();
console.log('Is email valid?', isEmailValid); // Output: true
// Example usage for password validation
const passwordValidator = new DataValidation('Passw0rd!');
const isPasswordValid = passwordValidator.validatePassword();
console.log('Is password valid?', isPasswordValid); // Output: true
// Example usage for custom validation
const customValidator = new DataValidation('CustomData');
const isCustomValid = customValidator.validateCustom('^Custom.*$');
console.log('Is custom data valid?', isCustomValid); // Output: true
Creates a new instance of DataValidation with the provided data.
-
data
: String - The data to be validated.
Validates the email format of the provided data.
Returns true
if the email format is valid, otherwise false
.
Validates the password format of the provided data.
Returns true
if the password format is valid, otherwise false
.
Validates the date format of the provided data.
Returns true
if the date format is valid, otherwise false
.
Validates the provided data against a custom regular expression.
-
regex
: String - The custom regular expression pattern to validate against.
Returns true
if the data matches the custom regex pattern, otherwise false
.
This project is licensed under the MIT License - see the LICENSE file for details.