This validation function will validate Regex numeric, alphaonly, alphanumeric, alphanumericwithspecialchar, email
npm i regex-validationIt'll accept two parameters-
1. Original Data
2. Validation Type
It'll return a boolean.
Parameters | Data Type | Mandatory | Description |
---|---|---|---|
Original Data | string | Yes | Need to send value, which needs to be validated |
Validation Type | string | Yes | Need to send type of validation (numeric, alpha-numeric, alphabets-with-space) |
Import the package from:
const validateRegexData= require('regex-validation') or import validateRegexData from 'regex-validation';
Use the function:
console.log(validateRegexData("123E45","numeric"))
Use case # 1:
Requirement:
If the original data is 123E45
(which you want numeric regex validation)
Use:
validateRegexData("123E45","numeric");
Output: false
.
Use case # 2:
Requirement:
If the original data is 123E45
(which you want alpha-numeric regex validation)
Use:
validateRegexData("123E45","alpha-numeric");
Output: true
.
Use case # 3:
Requirement:
If the original data is Demo Data
(which you want alphabets-with-space regex validation)
Use:
validateRegexData("Demo Data","alphabets-with-space");
Output: true
.
Others regex validation type will be added