1.0.1-0.11 • Published 5 years ago

validations-lib v1.0.1-0.11

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Validations-lib

This library contains all types of validations required for Node and Angular 6

How to use it:

Javascript

var validationsLib=required('validations-lib');

Angular app

import {Validation,FieldValidation} from 'validations-lib'

required object

var object = {
     title: 'number 1',
     type: 'number',
     required:true,
     condition: 'gt',
     currentValue: '1',
     message: 'number 1 must be greater than 25 ',
     params: [25],
     uid:'#1'
}

Pass your object into this validations-lib

javascript

var result= validationsLib.Validation.validate(object)

#### typescript node 8+
```ruby 
var result= Validation.validate(new FieldValidation(object))

Your output will be

{'result':false,message:'number 1 must be greater than 25'}

Description of the base object

PropertyDetailsDefault
titleValidation(field) Title(string)blank
typeField Type(type of question)text
conditionConditons like greater thanblank
currentValueInput (Field input)blank
messageCustomise your messagelib generated
paramsCompare the valuesblank
requiredRequired fieldsfalse
uidUnique identifier(numeric-optional)blank

Title

Your field or Validation Title

Input Type(s)

TypesDetails
textBy default it is text type
numberAllows only number type
multiselect-dropdownAllows only single dimensional arrray of elements
dateDate format (moment js)
timeTime format (moment js)
datetimeAllow date with time
timeRangeAllows an array of time time1,time2 or [time1,time2]
dateRangeAllows an array of date date1,date2 or [date1,date2]
dateTimeRangeAllows an array of date with time datetime1,datetime2 or [datetime1,datetime2]

Condition(s) applied on fields

TypesDetailsSupport
gtGreater thanall types
ltLess thanall types
eqEqual toall types
lteLess than or equal toall types
gteGreater than or equal toall types
notEqualNot equal toall types
betweenBetweenall types except(ranges)
notBetweenNot Betweenall types except(ranges)
sameAsThis condition is only for text type (String match)text
notSameThis condition is only for text type (String does not match)text
containsText contains (String that contains specific string of character/s)text
notContainsText not contains (String that does not contain specific string of character/s)text
startwithText start with (String starting with a particular character/s)text
endswithText ends with (String starting with a particular character/s)text

Message

One can have their own customised validation messages otherwise validations-lib provides default messages as well.

Params

Based on the validations-lib here you can pass maximumm 2 parameters as mentioned below

TypesDetails
minMinimun number of elements
maxMaximum number of elements

If one wants to set min value and max value one by one (one after the other) then one can use setParams() method with one argument.

Required (optional)

If you pass a boolean value in this object then it will give you appropriate message accordingly with UID otherwise by default it will return false.

uid (Unique ID)

This property contains unique identification of an object.

Example

If you pass two parameters then it considers is as 'between' or 'not between' case.

In case of 'between' your object will be something like as shown below:

var object ={
     title: 'number 1',
     type: 'number',
     required:true,
     condition: 'between',
     currentValue: '1',
     message: 'number 1 must be between than 25 to 30',
     params: [25,30],
     uid:'#1'
}

Multiple Field Validation

If you have a bunch of fields for validation in a single object, then we have to providee uid in question as well as entry object

Example

var object = [
  {
       title: 'number 1',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 1 must be between than 25 to 30',
       params: [25,30],
       uid:'#1'
  },
  {
       title: 'number 2',
       type: 'number',
       required:true,
       condition: 'between',
       message: 'number 2 must be between than 25 to 30',
       params: [25,30],
       uid:'#2'
  },
  {
       title: 'number 3',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 3 must be between than 20 to 30',
       params: [20,30],
       uid:'#3'
  },
  {
       title: 'number 4',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 4 must be between than 25 to 30',
       params: [25,30],
       uid:'#4'
  }
]  

And your final input object will look something like below:

var entry = {
'#1':1,
'#2':2,
'#3':40,
'#4':6
}
var result = validationsLib.validateWithGroup(entry,object)

Output

{
'#1':{'result':false,message:'number 1 must be between than 25 to 30'},
'#2':{'result':false,message:'number 2 must be between than 25 to 30'},
'#3':{'result':false,message:'number 3 must be between than 20 to 30'},
'#4':{'result':false,message:'number 4 must be between than 25 to 30'}
}

Comparison with another question

If you want to compare your question with another question then specify uid in params, then your object will look something like this

 {
       title: 'number 4',
       type: 'number',
       required:true,
       condition: 'between',
        message: 'number 4 must be between than 25 to #3 value',
       params: [25,'#3'],
       uid:'#4'
  }
### output
**result** Key 'all' field is valid or not
```ruby
{
'#1':{'result':false,message:'number 1 must be between than 25 to 30'},
'#2':{'result':false,message:'number 2 must be between than 25 to 30'},
'#3':{'result':false,message:'number 3 must be between than 20 to 30'},
'#4':{'result':false,message:'number 4 must be between than 25 to 40'}
'result':false
}

For any other requirements

Feel free to mail me at saurabhrathod35@gmail.com

github URL

https://github.com/saurabhrathod35/validations-lib

1.0.1-0.11

5 years ago

1.0.1-0.10

5 years ago

1.0.1-0.9

5 years ago

1.0.1-0.8

5 years ago

1.0.1-0.7

5 years ago

1.0.1-0.6

5 years ago

1.0.1-0.5

5 years ago

1.0.1-0.4

5 years ago

1.0.1-0.3

5 years ago

1.0.1-0.2

5 years ago

1.0.1-0.1

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago