Socket
Socket
Sign inDemoInstall

validator

Package Overview
Dependencies
Maintainers
0
Versions
211
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validator - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

66

lib/validator.js

@@ -8,2 +8,3 @@ var net = require('net');

this.msg = fail_msg;
this._errors = [];
return this;

@@ -18,2 +19,3 @@ }

throw new Error(msg);
return this;
}

@@ -23,3 +25,3 @@

if (!this.str.match(/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/)) {
this.error(this.msg || 'Invalid email');
return this.error(this.msg || 'Invalid email');
}

@@ -31,3 +33,3 @@ return this;

if (!this.str.match(/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?((?:(?:[-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2}))|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/)) {
this.error(this.msg || 'Invalid URL');
return this.error(this.msg || 'Invalid URL');
}

@@ -41,7 +43,7 @@ return this;

if (net.isIP(this.str) === 0) {
this.error(this.msg || 'Invalid IP');
return this.error(this.msg || 'Invalid IP');
}
} else {
if (!this.str.match(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/)) {
this.error(this.msg || 'Invalid IP');
return this.error(this.msg || 'Invalid IP');
}

@@ -54,3 +56,3 @@ }

if (!this.str.match(/^[a-zA-Z]+$/)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -62,3 +64,3 @@ return this;

if (!this.str.match(/^[a-zA-Z0-9]+$/)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -70,3 +72,3 @@ return this;

if (!this.str.match(/^-?[0-9]+$/)) {
this.error(this.msg || 'Invalid number');
return this.error(this.msg || 'Invalid number');
}

@@ -78,3 +80,3 @@ return this;

if (!this.str.match(/^[a-z0-9]+$/)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -86,3 +88,3 @@ return this;

if (!this.str.match(/^[A-Z0-9]+$/)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -94,3 +96,3 @@ return this;

if (!this.str.match(/^(?:-?(?:0|[1-9][0-9]*))$/)) {
this.error(this.msg || 'Invalid integer');
return this.error(this.msg || 'Invalid integer');
}

@@ -102,3 +104,3 @@ return this;

if (!this.str.match(/^(?:-?(?:0|[1-9][0-9]*))?(?:\.[0-9]*)?$/)) {
this.error(this.msg || 'Invalid decimal');
return this.error(this.msg || 'Invalid decimal');
}

@@ -114,3 +116,3 @@ return this;

if (this.str === '') {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -122,3 +124,3 @@ return this;

if (this.str !== '') {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -130,3 +132,3 @@ return this;

if (this.str.match(/^[\s\t\r\n]*$/)) {
this.error(this.msg || 'String is empty');
return this.error(this.msg || 'String is empty');
}

@@ -138,3 +140,3 @@ return this;

if (this.str != equals) {
this.error(this.msg || 'Not equal');
return this.error(this.msg || 'Not equal');
}

@@ -146,3 +148,3 @@ return this;

if (this.str.indexOf(str) === -1) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -154,3 +156,3 @@ return this;

if (this.str.indexOf(str) >= 0) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -165,3 +167,3 @@ return this;

if (! this.str.match(pattern)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -176,3 +178,3 @@ return this;

if (this.str.match(pattern)) {
this.error(this.msg || 'Invalid characters');
return this.error(this.msg || 'Invalid characters');
}

@@ -184,6 +186,6 @@ return this;

if (this.str.length < min) {
this.error(this.msg || 'String is too small');
return this.error(this.msg || 'String is too small');
}
if (typeof max !== undefined && this.str.length > max) {
this.error(this.msg || 'String is too large');
return this.error(this.msg || 'String is too large');
}

@@ -203,5 +205,25 @@ return this;

if (!this.str.match(pattern)) {
this.error(this.msg || 'Not a UUID');
return this.error(this.msg || 'Not a UUID');
}
return this;
}
Validator.prototype.isDate = function() {
var pattern = /^([0-1]{0,1}[0-9]{1})\/([0-3]{0,1}[0-9]{1})\/([0-9]{4})$/;
var result = pattern.exec(this.str);
if (!result || result.length != 4 ) {
return this.error(this.msg || 'Not a date');
}
var dt = new Date(this.str);
if ( dt.getFullYear() != parseInt(result[3])
|| dt.getMonth() + 1 != parseInt(result[1])
|| dt.getDate() != parseInt(result[2])
) {
return this.error(this.msg || 'Not a date');
}
return this;
};
{ "name" : "validator",
"description" : "Data validation, filtering and sanitization for node.js",
"version" : "0.2.1",
"version" : "0.2.2",
"homepage" : "http://github.com/chriso/node-validator",

@@ -18,3 +18,4 @@ "keywords" : ["validator", "validation", "assert", "params", "sanitization", "xss", "entities", "sanitize", "sanitisation", "input"],

"contributors": [
{ "name": "PING", "github": "https://github.com/PlNG" }
{ "name": "PING", "github": "https://github.com/PlNG" },
{ "name": "Dan VerWeire", "github": "https://github.com/wankdanker" }
],

@@ -21,0 +22,0 @@ "engines" : { "node" : ">=0.2.2" },

@@ -140,3 +140,4 @@ **node-validator is a library of string validation, filtering and sanitization methods.**

[PING](https://github.com/PlNG) - Fixed entity encoding
- [PING](https://github.com/PlNG) - Fixed entity encoding
- [Dan VerWeire](https://github.com/wankdanker) - Modified the behaviour of the error handler

@@ -143,0 +144,0 @@ ## LICENSE

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc