Skip to content

Commit

Permalink
Fix order of validation for phone extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
zgong-gov committed Jan 11, 2025
1 parent 8a61792 commit 8f2a599
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions frontend/src/common/helpers/phone/validatePhoneExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { invalidExtension, invalidExtensionLength } from "../validationMessages"
export const validatePhoneExtension = (ext?: Nullable<string>) => {
if (!ext) return true; // empty or not-provided phone extension is acceptable

if (ext.length > 5) return invalidExtensionLength(5);

// Must have exactly 1-5 digits
if (!/^[0-9]{1,5}$/.test(ext)) return invalidExtension();
return ext.length <= 5 || invalidExtensionLength(5);
return /^[0-9]{1,5}$/.test(ext) || invalidExtension();
};

0 comments on commit 8f2a599

Please sign in to comment.