I am trying to do the text field that will accept only numbers in the format like phone number: xxx-xxx-xxx. I dont want to use the basic thext field format of type="number". Here is my code:
const PatientEditScreen = ({ match }) => {
const patientId = match.params.id;
const [phone, setPhone] = useState(0);
useEffect(() => {
if (!patient.name || patient._id !== patientId) {
dispatch(listPatientDetails(patientId));
} else {
setPhone(patient.phone);
}
}, [dispatch, patientId, patient]);
return (
<>
<h1>Edit Patient</h1>
<Card className="mb-3 border-dark">
<Card.Body>
<Form onSubmit={submitHandler}>
<Form.Row>
<Form.Group controlId="phone" as={Col} variant="flush">
<Form.Label as="h5">Phone Number</Form.Label>
<Form.Control
type="number"
pattern="[0-9]*"
placeholder="Enter Phone Number"
value={phone}
onChange={(e) => setPhone(e.target.value)}
></Form.Control>
</Form.Group>
</Form.Row>
</Form>
</Card.Body>
</Card>
)}
</>
);
};
export default PatientEditScreen;