diff --git a/public/locales/en.json b/public/locales/en.json index 7f07275c54..b99a8875fa 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -10,6 +10,10 @@ "email": "Email", "password": "Password", "atleast_8_char_long": "Atleast 8 Character long", + "atleast_6_char_long": "Atleast 6 Character long", + "firstName_invalid": "First name should contain only lower and upper case letters", + "lastName_invalid": "First name should contain only lower and upper case letters", + "password_invalid": "Password should contain atleast one lowercase, one uppercase, one numeric value and one special character", "Password_and_Confirm_password_mismatches.": "Password and Confirm password mismatches.", "confirmPassword": "Confirm Password", "forgotPassword": "Forgot Password ?", diff --git a/src/screens/LoginPage/LoginPage.tsx b/src/screens/LoginPage/LoginPage.tsx index 44afdbacb9..13231093c0 100644 --- a/src/screens/LoginPage/LoginPage.tsx +++ b/src/screens/LoginPage/LoginPage.tsx @@ -129,12 +129,34 @@ function loginPage(): JSX.Element { toast.error(t('Please_check_the_captcha')); return; } + const isValidatedString = (value: string): boolean => + /^[a-zA-Z]+$/.test(value); + + const validatePassword = (password: string): boolean => { + const lengthCheck = new RegExp('^.{7,}$'); + const lowercaseCheck = new RegExp('[a-z]'); + const uppercaseCheck = new RegExp('[A-Z]'); + const numericalCheck = new RegExp('\\d'); + const specialCharCheck = new RegExp( + '[!@#$%^&*()_+{}\\[\\]:;<>,.?~\\\\/-]' + ); + return ( + lengthCheck.test(password) && + lowercaseCheck.test(password) && + uppercaseCheck.test(password) && + numericalCheck.test(password) && + specialCharCheck.test(password) + ); + }; if ( + isValidatedString(signfirstName) && + isValidatedString(signlastName) && signfirstName.length > 1 && signlastName.length > 1 && signEmail.length >= 8 && - signPassword.length > 1 + signPassword.length > 1 && + validatePassword(signPassword) ) { if (cPassword == signPassword) { try { @@ -153,8 +175,6 @@ function loginPage(): JSX.Element { 'Successfully Registered. Please wait until you will be approved.' ); - setShowTab('LOGIN'); - setSignFormState({ signfirstName: '', signlastName: '', @@ -171,7 +191,18 @@ function loginPage(): JSX.Element { toast.warn(t('passwordMismatches')); } } else { - toast.warn(t('fillCorrectly')); + if (!isValidatedString(signfirstName)) { + toast.warn(t('firstName_invalid')); + } + if (!isValidatedString(signlastName)) { + toast.warn(t('lastName_invalid')); + } + if (!validatePassword(signPassword)) { + toast.warn(t('password_invalid')); + } + if (signEmail.length < 8) { + toast.warn(t('email_invalid')); + } } }; @@ -520,22 +551,22 @@ function loginPage(): JSX.Element { {isInputFocused && - signformState.signPassword.length < 8 && ( + signformState.signPassword.length < 6 && (
- {t('atleast_8_char_long')} + {t('atleast_6_char_long')}
)} {!isInputFocused && signformState.signPassword.length > 0 && - signformState.signPassword.length < 8 && ( + signformState.signPassword.length < 6 && (
- {t('atleast_8_char_long')} + {t('atleast_6_char_long')}
)}