Skip to content

Commit bf88766

Browse files
authored
Merge pull request #273 from rosyntow/bugfix-#272
modified the phone number regex to accept more valid formats during signup
2 parents f104220 + 8ab56b9 commit bf88766

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

frontend/models/primary-input.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum PrimaryInputNames {
2222
const passwordRgx: RegExp = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z\d\s]).{8,}$/
2323
const nameRgx: RegExp = new RegExp("^[' -]*[a-z]+[a-z' -]+$", "i")
2424
const anyString: RegExp = new RegExp("[sS]*")
25+
const phoneNumberRgx: RegExp = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/
2526

2627
export const primaryInputValidation = {
2728
[PrimaryInputNames.BADGE_NUMBER]: {
@@ -81,8 +82,8 @@ export const primaryInputValidation = {
8182
inputType: "text"
8283
},
8384
[PrimaryInputNames.PHONE_NUMBER]: {
84-
errorMessage: 'A phone number is required, formatted as "123 456 7890"',
85-
pattern: /\d{3} \d{3} \d{4}/,
85+
errorMessage: "A valid phone number is required",
86+
pattern: phoneNumberRgx,
8687
inputType: "tel"
8788
},
8889
[PrimaryInputNames.LOGIN_PASSWORD]: {

frontend/tests/snapshots/register.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ describe("behaviors", () => {
4646
}
4747
})
4848

49-
it("checks phone formatting", async () => {
49+
it("checks phone number length", async () => {
5050
const r = renderPage()
5151
act(() => {
52-
userEvent.type(r.phoneNumber, "5555555555")
52+
userEvent.type(r.phoneNumber, "5555555555555")
5353
userEvent.click(r.submit)
5454
})
5555
await expect(r.findByText(/phone number is required/)).resolves.toBeInTheDocument()

0 commit comments

Comments
 (0)