
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
js-validate
Advanced tools
Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect.
Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect.
npm install js-validate
const Validator = require('js-validate');
const validate = new Validator;
Validate against a single rule:
validate('123', 'min-length 2'); //--> true
Validate against multiple rules:
validate('123', ['min-length 2', 'number']); //-->true
Create a validator alias (single-rule):
Validator.alias('short', 'max-length 3');
Create a validator alias (multiple rules):
Validator.alias('account-number', [
'alphanumeric -',
'min-length 7',
'starts-with 000-',
'ends-with -00'
]);
Create a custom rule:
Validator.rule('isOkay', (input) => {
return String(input).toLowerCase() === 'ok';
});
Integrate other great validators:
const tin = require('tin-validator');
Validator.rule('ssn-ein-tin', tin.isValid);
Test custom rules and aliases:
validate('ok', 'isOkay'); //--> true
validate('OK', ['isOkay', 'short']); //--> true
validate('000-23422823934-00', 'account-number'); //--> true
validate('Abc', 'alpha'); //--> truevalidate('ABC123', 'alpha'); //--> falsevalidate('abc123', 'alphanumeric'); //--> truevalidate('123 Main Street', 'alphanumeric'); //--> falsevalidate('123 Main Street', 'alphanumeric _space_'); //--> truevalidate('true', 'boolean'); //--> truevalidate('false', boolean'); //--> truevalidate(FALSE, 'boolean'); //--> truevalidate('JoJo', 'capitals 2'); //--> truevalidate('abc123', 'endsWith 123'); //--> truevalidate('555-888-0000', 'endsWith 0'); //--> truevalidate('abc', 'equal abc'); //--> truevalidate('abc', 'equal ABC'); //--> falsevalidate('123', 'equal 123'); //--> truevalidate(123, 'equal 123'); //--> falsevalidate(123, 'length 3'); //--> truevalidate(000123, 'length 6'); //--> falsevalidate(000123, 'length 2'); //--> truevalidate('000123', 'length 6'); //--> truevalidate('123', 'matches 123'); //--> truevalidate(123, 'matches 123'); //--> true validate('123', 'matches 123'); //--> truevalidate(123, 'matches 123'); //--> false validate(123, 'max 125'); //--> truevalidate(123, 'max-length 3'); //--> truevalidate(123, 'max-length 2'); //--> falsevalidate(123, 'min 122'); //--> truevalidate(123, 'min-length 3'); //--> truevalidate(123, 'min-length 4'); //--> falsevalidate('50.00'', 'number'); //--> truevalidate('50A', 'number'); //--> falsevalidate('#1 Fan', 'numbers 1'); //--> truevalidate('Catch 22', 'numbers 1'); //--> falsevalidate('123', 'numeric'); //--> truevalidate(123, 'numeric'); //--> truevalidate('ABC123', 'numeric'); //--> falsevalidate('ABC123', 'specials 0'); //--> truevalidate('ABC*123', 'specials 1'); //--> truevalidate('Hello!!!', 'specials 3'); //--> truevalidate('$1', 'starts-with $'); //--> truevalidate('ABC123', 'starts-with ABC'); //--> truevalidate('ABC123', 'starts-with abc'); //--> falseWe need to greatly expand the rules, prune, and modify them. We are also open to changes in the API of this utility. Make and issue on github to connect.
FAQs
Functional, extensible, input validation. Make sure the value you receive is EXACTLY what you expect.
We found that js-validate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.