-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TextField] type='number' formatting #36415
Comments
Thanks for reporting this ~ @VishnuCabot These are common issues when using the HTML I think the simple workaround mentioned in the docs involving the HTML If you are trying to restrict to positive integers only, maybe you could try adding that check in your const handleChange = (event) => {
if (event.target.value.match(/[^0-9]/)) {
event.preventDefault();
}
// otherwise, continue with the rest of your logic
// ...
}
...
<TextField
id="phone_number"
label="Phone Number"
variant="outlined"
inputProps={{ inputMode: 'numeric' }}
onChange={handleChange}
/> We're also working on a proper number input component: #19154 |
Hi @mj12albert ,
You know, as a developer, you should be looking for every possible solutions out there, right 😬😀?! I tried many ways without trying out any external libraries and was checking whether I could do anything with the type="number" field. It would be very much helpful if anyone could answer my query with a helping solution. Attaching the solution I have implemented to get through the same scenario I have described. The particular code is for ZIP input which is a 5 digit number of format { xxxxx } and will not accept 0 as first digit.
<Controller
|
👋 Thanks for using MUI Core! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://mui.com/getting-started/support/. Thanks! If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. |
@VishnuCabot Have a look at this sandbox to see how to restrict the input to numbers only: https://codesandbox.io/s/https-github-com-mui-material-ui-issues-36415-orxx4r?file=/src/App.tsx We do not recommend using using For formatting/masking the display to |
I have an Material UI TextField of type 'number'. That field should take only positive integers (when on typing and on pasting values to the field) and should not display scroll or should not respond to mouse wheel scroll or keyboard arrows. how should I do this ? ( scroll icons can be removed with CSS anyway )
Any help would be very much appreciated. Thank You!
The text was updated successfully, but these errors were encountered: