A lightweight JavaScript library for data validation in Node.js and browser environments.
You can install the Data Validation Library via npm:
npm install vader-data-validator
const DataValidator = require('data-validation-library');
// Validate a string
try {
DataValidator.validateString('hello', 3, 10); // Valid string with length between 3 and 10 characters
console.log('String is valid');
} catch (error) {
console.error(error.message);
}
// Validate a number
try {
DataValidator.validateNumber(42, 0, 100); // Valid number between 0 and 100
console.log('Number is valid');
} catch (error) {
console.error(error.message);
}
// Validate an email
try {
DataValidator.validateEmail('example@example.com'); // Valid email format
console.log('Email is valid');
} catch (error) {
console.error(error.message);
}
Validates a string with optional minimum and maximum lengths.
-
value
: The string to validate. -
minLength
: Optional minimum length of the string. -
maxLength
: Optional maximum length of the string.
Validates a number with optional minimum and maximum values.
-
value
: The number to validate. -
min
: Optional minimum value of the number. -
max
: Optional maximum value of the number.
Validates an email address using a basic regular expression.
-
value
: The email address to validate.
This project is licensed under the MIT License - see the LICENSE file for details.