Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

m-validate

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m-validate - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

package.json
{
"name": "m-validate",
"version": "1.0.1",
"version": "1.0.2",
"description": "NodeJS simple validation functions",

@@ -5,0 +5,0 @@ "main": "m-validate.js",

@@ -8,3 +8,3 @@ # m-validate

Moblets' NodeJS simple validation to validate data based on a deffinition JSon.
Moblets' NodeJS simple validation to validate data based on a definition JSon.

@@ -17,3 +17,385 @@ ## Installation

## Available validations
Validations were created for **input type**, **length**, **required** and **string**.
### Input type validation
These are all HTML 5 input type validations.
#### number
Check input type number for integers.
**Usage**
Definition JSon
```json
{
"name": "Number of friends",
"type": "number"
}
```
**Error response:** *not_a_number*
#### select, radio and checkbox
Check if the response belongs to the possible values.
**Usage**
Definition JSon
```json
{
"name": "position",
"type": "radio",
"values": {
"left": "value_left",
"right": "value_right",
"up": "value_up",
"down": "value_down"
}
}
```
If the value is _left, right, up or down_, it will be validated.
**Error response:** *not_in_the_select_list*, *not_in_the_radio_list* or *not_in_the_checkbox_list*
#### color
Check if the response is a valid HTML 5, hexadecimal color, like '#FF0033'.
**Usage**
Definition JSon
```json
{
"name": "themeColor",
"type": "color"
}
```
**Error response:** *not_a_color*
#### date
Check if the response is a valid HTML 5, 'YYYY-MM-DD' date.
**Usage**
Definition JSon
```json
{
"name": "birthDay",
"type": "date"
}
```
**Error response:** *not_a_date*
#### time
Check if the response is a valid HTML 5, 'H:mm' time.
**Usage**
Definition JSon
```json
{
"name": "arrival",
"type": "time"
}
```
**Error response:** *not_a_time*
#### email
Check if the response is a valid email.
**Usage**
Definition JSon
```json
{
"name": "userEmail",
"type": "email"
}
```
**Error response:** *not_an_email*
#### url
Check if the response is a valid url.
**Usage**
Definition JSon
```json
{
"name": "siteUrl",
"type": "url"
}
```
**Error response:** *not_an_url*
#### tel
Check if the response is a phone. It's a generic phone validator that accepts international (with plus sign) and local phones (with or without paranthesis).
**Usage**
Definition JSon
```json
{
"name": "cellNumber",
"type": "tel"
}
```
**Error response:** *not_a_tel*
### Length validation
These two validations are for generic strings to define it's min and max length.
**Usage**
Definition JSon
```json
{
"name": "pinCode",
"min-length": 4,
"max-length": 8
}
```
**Error response:** *must_be_min: 4* or *must_be_max: 8*
### Required validation
This validation checks if the required value is available in the POST JSon.
**Usage**
Definition JSon
```json
{
"name": "name",
"required": true
}
```
**Error response:** *field_is_required*
### String validations
These are validations for specific kinds of strings, that must help creating validations tom many field types.
#### alpha
This validation require the data to be only letters and accented letters (A-z and À-ÿ).
**Usage**
Definition JSon
```json
{
"name": "firstName",
"type": "text",
"string": "alpha"
}
```
**Error response:** *not_an_alpha*
#### alphaSpace
This validation require the data to be only letters, accented letters and spaces (A-z, À-ÿ and ' ').
**Usage**
Definition JSon
```json
{
"name": "fullName",
"type": "text",
"string": "alphaSpace"
}
```
**Error response:** *not_an_alpha_space*
#### alphaDash
This validation require the data to be only letters, accented letters and dashes (A-z, À-ÿ, - and \_).
**Usage**
Definition JSon
```json
{
"name": "serialNumber",
"type": "text",
"string": "alphaDash"
}
```
**Error response:** *not_an_alpha_dash*
#### alphaSymbol
This validation require the data to be letters, accented letters and many symbols:
| A-z | À-ÿ | \- | _ | . | , | ! | @ |
|-------|-------|-------|-------|-------|-------|-------|-------|
| **#** | **$** | **%** | **^** | **{** | **}** | **[** | **]** |
| **&** | **\*** | **(** | **)** | **<** | **>** | **+** | **=** |
| **?** | **:** | **;** | **"&nbsp;"** |
**Usage**
Definition JSon
```json
{
"name": "address",
"type": "text",
"string": "alphaSymbol"
}
```
**Error response:** *not_an_alpha_symbol*
#### alphaNumeric
This validation require the data to be letters, accented letters and numbers (A-z, À-ÿ and 0-9).
**Usage**
Definition JSon
```json
{
"name": "code",
"type": "text",
"string": "alphaNumeric"
}
```
**Error response:** *not_an_alpha_numeric*
#### alphaNumericSpace
This validation require the data to be letters, accented letters, numbers and space (A-z, À-ÿ, 0-9 and ' ').
**Usage**
Definition JSon
```json
{
"name": "keyCode",
"type": "text",
"string": "alphaNumericSpace"
}
```
**Error response:** *not_an_alpha_numeric_space*
#### alphaNumericDash
This validation require the data to be letters, accented letters, numbers and space (A-z, À-ÿ, 0-9, - and \_).
**Usage**
Definition JSon
```json
{
"name": "serialNumber",
"type": "text",
"string": "alphaNumericDash"
}
```
**Error response:** *not_an_alpha_numeric_dash*
#### alphaNumericSymbol
This validation require the data to be letters, accented letters, numbers and many symbols:
| A-z | À-ÿ | 0-9 | "&nbsp;" | . | , | ! | @ |
|-------|-------|-------|-------|-------|-------|-------|-------|
| **#** | **$** | **%** | **^** | **&** | **\*** | **(** | **)** |
| **{** | **}** | **[** | **]** | **<** | **>** | **+** | **=** |
| **?** | **:** | **;** | **-** | **\_** | | | |
**Usage**
Definition JSon
```json
{
"name": "serialNumber",
"type": "text",
"string": "alphaNumericSymbol"
}
```
**Error response:** *not_an_alpha_numeric_symbol*
#### numeric
This validation require the data to be numbers (0-9).
**Usage**
Definition JSon
```json
{
"name": "products",
"type": "text",
"string": "numeric"
}
```
**Error response:** *not_a_numeric*
#### numericFloat
This validation require the data to be numbers, -, . and , (0-9.,-).
**Usage**
Definition JSon
```json
{
"name": "price",
"type": "text",
"string": "numericFloat"
}
```
**Error response:** *not_a_numeric_float*
#### numericDash
This validation require the data to be numbers, -, \_, . and , (0-9.,-\_).
**Usage**
Definition JSon
```json
{
"name": "balance",
"type": "text",
"string": "numericDash"
}
```
**Error response:** *not_a_numeric_dash*
#### numericSymbol
This validation require the data to be numbers and many symbols:
| 0-9 | "&nbsp;" | 0-9 | _ | . | , | ! | @ |
|-------|-------|-------|-------|-------|-------|-------|-------|
| **#** | **$** | **%** | **^** | **&** | **\*** | **(** | **)** |
| **{** | **}** | **[** | **]** | **<** | **>** | **+** | **=** |
| **?** | **:** | **;** | **-** |
**Usage**
Definition JSon
```json
{
"name": "code",
"type": "text",
"string": "numericSymbol"
}
```
**Error response:** *not_a_numeric_symbol*
## Pre requisites

@@ -20,0 +402,0 @@

@@ -30,3 +30,3 @@ /* eslint-env jasmine */

expect(result.result.password['max-length'])
.toBe('must_be_more_than_chars: 4');
.toBe('must_be_max: 4');
});

@@ -42,4 +42,4 @@

expect(result.result.password['min-length'])
.toBe('must_be_at_least_chars: 4');
.toBe('must_be_min: 4');
});
});

@@ -5,3 +5,3 @@ module.exports = {

if (theData !== undefined && theLength > theData.length) {
response = 'must_be_at_least_chars: ' + theLength;
response = 'must_be_min: ' + theLength;
}

@@ -13,3 +13,3 @@ return response;

if (theData !== undefined && theLength < theData.length) {
response = 'must_be_more_than_chars: ' + theLength;
response = 'must_be_max: ' + theLength;
}

@@ -16,0 +16,0 @@ return response;

@@ -64,3 +64,3 @@ module.exports = function(theType, theData) {

case "numericFloat":
var numericSpace = /^[0-9.,]*$/;
var numericSpace = /^[0-9.,\-]*$/;
if (!numericSpace.test(theData)) {

@@ -67,0 +67,0 @@ response = 'not_a_numeric_float';

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