Skip to content

Commit 35b1b3f

Browse files
authored
Merge pull request #2 from amarpathak/password-validation
Password Validation Added
2 parents 8780158 + 465c659 commit 35b1b3f

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/Validations/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ export const validateOption = (value, message) => {
3939
}
4040
return validationProps(false, '');
4141
};
42+
43+
export const validatePassword = (value, message, validLength = 6) => {
44+
if (isBlank(value) || value.length < validLength) {
45+
return validationProps(true, message);
46+
}
47+
return validationProps(false, '');
48+
};

src/__tests__/export.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
validateName,
1111
validateMobile,
1212
validateEmail,
13-
validateOption
13+
validateOption,
14+
validatePassword
1415
} from '../index';
1516

1617

src/__tests__/index.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
validateName,
1111
validateMobile,
1212
validateEmail,
13-
validateOption
13+
validateOption,
14+
validatePassword
1415
} from '../index';
1516

1617
// CamelCase String //
@@ -116,3 +117,11 @@ test('should validate option and return no error object', () => (
116117
test('should validate option and return error object', () => (
117118
expect(validateOption('', 'Please select an option')).toEqual({ error: true, errorMessage: 'Please select an option'})
118119
));
120+
//Validate Password
121+
test('should validate Password and return error', () => (
122+
expect(validatePassword('12345', 'Password Must be altleast 6 characters')).toEqual({ error: true, errorMessage: 'Password Must be altleast 6 characters'})
123+
));
124+
125+
test('should validate Password and should not return error', () => (
126+
expect(validateOption('123456', '')).toEqual({ error: false, errorMessage: ''})
127+
));

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
validateName,
1313
validateMobile,
1414
validateEmail,
15+
validatePassword,
1516
validateOption
1617
} from './Validations';
1718

@@ -30,5 +31,7 @@ export {
3031
validateName,
3132
validateMobile,
3233
validateEmail,
33-
validateOption
34+
validatePassword,
35+
validateOption,
36+
3437
};

0 commit comments

Comments
 (0)