Skip to content

Commit

Permalink
Merge pull request #9213 from ohcnetwork/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar authored Nov 26, 2024
2 parents 30739f1 + 10b562e commit a8985fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@
"middleware_hostname": "Middleware Hostname",
"middleware_hostname_example": "e.g. example.ohc.network",
"middleware_hostname_sourced_from": "Middleware hostname sourced from {{ source }}",
"min_char_length_error": "Must be at least {{ min_length }} characters",
"min_password_len_8": "Minimum password length 8",
"min_time_bw_doses": "Min. time b/w doses",
"minimize": "Minimize",
Expand Down
3 changes: 1 addition & 2 deletions src/common/validation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export const getRandomNumbers = (min: number, max: number) => {
};

export const validateName = (name: string) => {
const pattern = /^([a-zA-Z]*( [a-zA-Z])?)+$/;
return pattern.test(name);
return name.length >= 3;
};

export const validateUsername = (username: string) => {
Expand Down
12 changes: 8 additions & 4 deletions src/components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,16 @@ export const PatientRegister = (props: PatientRegisterProps) => {
Object.keys(form).forEach((field) => {
let phoneNumber, emergency_phone_number;
switch (field) {
case "address":
case "name":
if (!validateName(form[field])) {
errors[field] = "Please enter valid name";
case "name": {
const requiredError = RequiredFieldValidator()(form[field]);
if (requiredError) {
errors[field] = requiredError;
} else if (!validateName(form[field])) {
errors[field] = t("min_char_length_error", { min_length: 3 });
}
return;
}
case "address":
case "gender":
errors[field] = RequiredFieldValidator()(form[field]);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Users/UserAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export const UserAdd = (props: UserProps) => {
.join(" ")} is required`;
invalidForm = true;
} else if (!validateName(state.form[field])) {
errors[field] = "Please enter a valid name";
errors[field] = t("min_char_length_error", { min_length: 3 });
invalidForm = true;
}
return;
Expand Down

0 comments on commit a8985fc

Please sign in to comment.