Replies: 1 comment
-
I actually found the answer in the customization guide, which offers a highly versatile component, import { BaseTextFieldProps, TextField, TextFieldProps, TextFieldVariants } from "@mui/material";
import { formatIncompletePhoneNumber } from "libphonenumber-js";
import { NumberFormatBase, NumberFormatBaseProps } from "react-number-format";
const stripFormat = (s: string) => s.replaceAll(/[^0-9]+/g, "");
export const PhoneNumberTextField = ( props:NumberFormatBaseProps<BaseTextFieldProps>) => {
return (
<NumberFormatBase
variant="outlined"
format={(s: string) => formatIncompletePhoneNumber(s, "US")}
removeFormatting={(s: string) => stripFormat(s)}
customInput={TextField}
{...props}
/>
);
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I am wanting to migrate from version 4 to 5 but am encountering a problem with my telephone number fields. Currently the formatting is outsourced to
libphonenumber-js
by providing a format function, the props are like this:This solution works very well right now, and we would be reluctant to upgrade if it meant abandoning it. Now in
PatternFormat
theformat
prop only takes string, andremoveFormatting
does not exist. Am I missing something?Beta Was this translation helpful? Give feedback.
All reactions