diff --git a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
index df8f6600aa3..7fdbcad76af 100644
--- a/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
+++ b/src/components/ABDM/LinkAbhaNumber/CreateWithAadhaar.tsx
@@ -685,7 +685,7 @@ function ChooseAbhaAddress({
false,
)}
{validateRule(
- isNaN(Number(healthId[0])) && healthId[0] !== ".",
+ Number.isNaN(Number(healthId[0])) && healthId[0] !== ".",
t("abha_address_validation_start_error"),
false,
)}
diff --git a/src/components/Auth/ResetPassword.tsx b/src/components/Auth/ResetPassword.tsx
index 58c00157ed2..72642fbce38 100644
--- a/src/components/Auth/ResetPassword.tsx
+++ b/src/components/Auth/ResetPassword.tsx
@@ -158,10 +158,11 @@ export const ResetPassword = (props: any) => {
/>
{confirmPasswordInputInFocus &&
form.confirm.length > 0 &&
+ form.password.length > 0 &&
validateRule(
form.confirm === form.password,
"Confirm password should match the entered password",
- !form.password,
+ !form.password && form.password.length > 0,
)}
diff --git a/src/components/Users/UserProfile.tsx b/src/components/Users/UserProfile.tsx
index b6a583cb112..439aae81664 100644
--- a/src/components/Users/UserProfile.tsx
+++ b/src/components/Users/UserProfile.tsx
@@ -193,6 +193,30 @@ export default function UserProfile() {
},
);
+ const validatePassword = (password: string) => {
+ const rules = [
+ {
+ test: (p: string) => p.length >= 8,
+ message: "Password should be at least 8 characters long",
+ },
+ {
+ test: (p: string) => p !== p.toUpperCase(),
+ message: "Password should contain at least 1 lowercase letter",
+ },
+ {
+ test: (p: string) => p !== p.toLowerCase(),
+ message: "Password should contain at least 1 uppercase letter",
+ },
+ {
+ test: (p: string) => /\d/.test(p),
+ message: "Password should contain at least 1 number",
+ },
+ ];
+ return rules.map((rule) =>
+ validateRule(rule.test(password), rule.message, !password),
+ );
+ };
+
const validateNewPassword = (password: string) => {
if (
password.length < 8 ||
@@ -904,28 +928,7 @@ export default function UserProfile() {
required
/>
- {validateRule(
- changePasswordForm.new_password_1?.length >= 8,
- "Password should be atleast 8 characters long",
- !changePasswordForm.new_password_1,
- )}
- {validateRule(
- changePasswordForm.new_password_1 !==
- changePasswordForm.new_password_1.toUpperCase(),
- "Password should contain at least 1 lowercase letter",
- !changePasswordForm.new_password_1,
- )}
- {validateRule(
- changePasswordForm.new_password_1 !==
- changePasswordForm.new_password_1.toLowerCase(),
- "Password should contain at least 1 uppercase letter",
- !changePasswordForm.new_password_1,
- )}
- {validateRule(
- /\d/.test(changePasswordForm.new_password_1),
- "Password should contain at least 1 number",
- !changePasswordForm.new_password_1,
- )}
+ {validatePassword(changePasswordForm.new_password_1)}
@@ -948,7 +951,8 @@ export default function UserProfile() {
changePasswordForm.new_password_1 ===
changePasswordForm.new_password_2,
"Confirm password should match the new password",
- !changePasswordForm.new_password_1,
+ !changePasswordForm.new_password_1 &&
+ changePasswordForm.new_password_1.length > 0,
)}
)}