regexpvalidator
Version:
Validation for String, numbers and objects in javascript
181 lines (125 loc) • 3.49 kB
Markdown
and Objects in JavaScript using Regular Expressions
Install with [npm](https://www.npmjs.com)
```sh
$ npm install regexpvalidator --save
```
```
var regExpValidation = require('regexpvalidator')
```
RegExpValidator provides a range of APIs for you to validate and filter javascript data types
Method allows you to test if the string contain only letters
```
regExpValidation.containsOnlyLetters('regularExpressions')
//=> true
regExpValidation.containsOnlyLetters('REGULAREXPRESSSION')
//=> true
regExpValidation.containsOnlyLetters('a@a.com')
//=> false
regExpValidation.containsOnlyLetters('a123')
//=> false
regExpValidation.containsOnlyLetters(' ')
//=> false
regExpValidation.containsOnlyLetters('_$%#@')
//=> false
```
Method allows you to test if the string contain only small case letters
```
regExpValidation.containsOnlySmallCaseLetters('regularexpressions')
//=> true
regExpValidation.containsOnlySmallCaseLetters('regularExpressions')
//=> false
```
Method allows you to test if the string contain only capital case letters
```
regExpValidation.containsOnlyCapsLetters('REGULAREXPRESSIONS')
//=> true
regExpValidation.containsOnlySmallCaseLetters('ReGULaREXPreSSIONS')
//=> false
```
Method allows you to test if the pattern matches in the string
Method allows you to test if the string is a valid email
```
regExpValidation.isValidEmail('a@a.com')
//=> true
regExpValidation.isValidEmail('abcd')
//=> false
regExpValidation.isValidEmail(' ')
//=> false
regExpValidation.isValidEmail('_$%#@')
//=> false
```
Method allows you to test if the string is a valid number
```
regExpValidation.isNumber(45)
//=> true
regExpValidation.isNumber('65')
//=> true
regExpValidation.isNumber('-39')
//=> true
regExpValidation.isNumber('-0')
//=> true
regExpValidation.isNumber('-39myFox')
//=> false
```
Method allows you to test if the string is a valid decimal number
```
regExpValidation.isDecimalNumber(8.97)
//=> true
regExpValidation.isDecimalNumber('-8.74')
//=> true
regExpValidation.isDecimalNumber(45)
//=> false
regExpValidation.isDecimalNumber('-0.00')
//=> true
regExpValidation.isDecimalNumber('-39.088myFox')
//=> false
```
Method allows you to test if the string has n decimal places
```
regExpValidation.hasNDecimalPlaces(8.97,2)
//=> true
regExpValidation.hasNDecimalPlaces('-8.74',2)
//=> true
regExpValidation.hasNDecimalPlaces(45,0)
//=> true
regExpValidation.hasNDecimalPlaces('-8.74',3)
//=> false
regExpValidation.hasNDecimalPlaces('-0.00',2)
//=> true
```
Method allows you filter all the numbers in a string
```
regExpValidation.filterNumbers('abcd')
//=> ''
regExpValidation.filterNumbers(-39)
//=> '-39'
regExpValidation.filterNumbers('3_BOXES_HAVE_55_BALLS')
//=> '355'
```
Method allows you filter all the characters in a string
```
regExpValidation.filterCharacters('abcd')
//=> 'abcd'
regExpValidation.filterCharacters(-39)
//=> ''
regExpValidation.filterCharacters('3_BOXES_HAVE_55_BALLS')
//=> 'BOXESHAVEBALLS'
```
Validations Test For Strings, Numbers