Skip to content

Commit

Permalink
fix: remove name regex
Browse files Browse the repository at this point in the history
  • Loading branch information
imklau committed Nov 13, 2024
1 parent 9e99d78 commit dc44ede
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Textarea from "design-system/components/textarea"
import Button from "design-system/components/button"
import Checkbox from "design-system/components/checkbox"

import { firstNameRegex, emailRegex } from "shared/regex"
import { emailRegex } from "shared/regex"

import * as Styled from "./Form.styled"

Expand Down Expand Up @@ -61,10 +61,6 @@ const Form = ({ handleSubmit, submitting }) => {
value: 20,
message: "Maksymalna ilość znaków to 20",
},
pattern: {
value: firstNameRegex,
message: "Wpisz poprawne imię (tylko litery)",
},
})}
message={errors.firstName ? errors.firstName.message : ""}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Checkbox from "design-system/components/checkbox"
import Select from "design-system/components/select"
import Illustration from "design-system/components/illustration/Illustration"

import { firstNameRegex, lastNameRegex, emailRegex } from "shared/regex"
import { emailRegex } from "shared/regex"

import * as Styled from "./PaymentConfirmationForm.styled"

Expand Down Expand Up @@ -110,10 +110,6 @@ const PaymentConfirmationForm = ({ data }) => {
value: 30,
message: "Maksymalna ilość znaków to 30",
},
pattern: {
value: firstNameRegex,
message: "Wpisz poprawne imię (tylko litery)",
},
})}
message={errors.firstName ? errors.firstName.message : ""}
/>
Expand All @@ -124,23 +120,13 @@ const PaymentConfirmationForm = ({ data }) => {
state={determineInputState("lastName")}
{...register("lastName", {
required: "To pole jest wymagane",
validate: {
customLength: (value) => {
const includesDash = value.includes("-")
if (includesDash && value.length < 5) {
return "Każda część nazwiska musi mieć min. 2 znaki"
}
if (!includesDash && value.length < 2) {
return "Minimalna ilość znaków to 2"
}
if (value.length > 70) {
return "Maksymalna ilość znaków to 70"
}
if (lastNameRegex.test(value)) {
return "Wpisz poprawne nazwisko"
}
return true
},
minLength: {
value: 2,
message: "Minimalna ilość znaków to 2",
},
maxLength: {
value: 30,
message: "Maksymalna ilość znaków to 30",
},
})}
message={errors.lastName ? errors.lastName.message : ""}
Expand Down
4 changes: 1 addition & 3 deletions packages/shared/regex/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const firstNameRegex = /^[A-Za-z]+$/i
const lastNameRegex = !/^[A-Za-z]{2,}(-[A-Za-z]{2,})?$/i
const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/i

export { firstNameRegex, lastNameRegex, emailRegex }
export { emailRegex }

0 comments on commit dc44ede

Please sign in to comment.