diff --git a/src/Validations/index.js b/src/Validations/index.js index 8fa61f9..7f31b9e 100644 --- a/src/Validations/index.js +++ b/src/Validations/index.js @@ -39,3 +39,10 @@ export const validateOption = (value, message) => { } return validationProps(false, ''); }; + +export const validatePassword = (value, message, validLength = 6) => { + if (isBlank(value) || value.length < validLength) { + return validationProps(true, message); + } + return validationProps(false, ''); +}; diff --git a/src/__tests__/export.test.js b/src/__tests__/export.test.js index 814cb09..5a68b7e 100644 --- a/src/__tests__/export.test.js +++ b/src/__tests__/export.test.js @@ -10,7 +10,8 @@ import { validateName, validateMobile, validateEmail, - validateOption + validateOption, + validatePassword } from '../index'; diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index d59d491..d9bfc5c 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -10,7 +10,8 @@ import { validateName, validateMobile, validateEmail, - validateOption + validateOption, + validatePassword } from '../index'; // CamelCase String // @@ -116,3 +117,11 @@ test('should validate option and return no error object', () => ( test('should validate option and return error object', () => ( expect(validateOption('', 'Please select an option')).toEqual({ error: true, errorMessage: 'Please select an option'}) )); +//Validate Password +test('should validate Password and return error', () => ( + expect(validatePassword('12345', 'Password Must be altleast 6 characters')).toEqual({ error: true, errorMessage: 'Password Must be altleast 6 characters'}) +)); + +test('should validate Password and should not return error', () => ( + expect(validateOption('123456', '')).toEqual({ error: false, errorMessage: ''}) +)); diff --git a/src/index.js b/src/index.js index 613837f..7e578e5 100644 --- a/src/index.js +++ b/src/index.js @@ -12,6 +12,7 @@ import { validateName, validateMobile, validateEmail, + validatePassword, validateOption } from './Validations'; @@ -30,5 +31,7 @@ export { validateName, validateMobile, validateEmail, - validateOption + validatePassword, + validateOption, + };