Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email and phone input validation #2284

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react-gtm-module": "^2.0.11",
"react-helmet-async": "^1.3.0",
"react-map-gl": "^7.1.7",
"react-number-format": "^5.4.2",
"react-router-dom": "^6.10.0",
"react-scripts": "^5.0.1",
"react-virtuoso": "^4.1.0",
Expand Down
5 changes: 5 additions & 0 deletions client/src/components/Admin/OrganizationEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import Verification from "./OrganizationEdit/Verification";
import Label from "./ui/Label";
import Textarea from "./ui/Textarea";

const phoneRegExp = /^\(\d{3}\) \d{3}-\d{4}$/;

const HourSchema = Yup.object().shape({
weekOfMonth: Yup.number().required("Interval is required"),
dayOfWeek: Yup.string().required("Day is required"),
Expand All @@ -43,6 +45,9 @@ const HourSchema = Yup.object().shape({

const validationSchema = Yup.object().shape({
name: Yup.string().required("Name is required"),
phone: Yup.string()
.matches(phoneRegExp, "Invalid phone number")
.required("Phone number is required"),
address1: Yup.string().required("Street address is required"),
city: Yup.string().required("City is required"),
state: Yup.string().required("State is required"),
Expand Down
11 changes: 9 additions & 2 deletions client/src/components/Admin/OrganizationEdit/Identification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import * as awsService from "services/aws-service";
import { disabledText, error as errorColor } from "theme/palette";
import Label from "../ui/Label";
import Textarea from "../ui/Textarea";
import { PatternFormat } from "react-number-format";


const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
Expand Down Expand Up @@ -117,12 +119,17 @@ export default function Identification({
label="Phone"
tooltipTitle="Phone number for clients to use"
/>
<TextField
<PatternFormat
format="(###) ###-####"
customInput={TextField}
mask="_"
id="phone"
name="phone"
placeholder="Phone"
value={values.phone}
onChange={handleChange}
onValueChange={(formattedValues) => {
setFieldValue("phone", formattedValues.formattedValue);
}}
onBlur={handleBlur}
helperText={touched.phone ? errors.phone : ""}
error={touched.phone && Boolean(errors.phone)}
Expand Down