how to make an input field that only allows numbers ?
that's an very beginner question. How to only allow number's in an input field BUT with out the usage of dedicated Signal's for an field or anything really complicated ?
(I am using TypeScript )
It would also have to include float numbers
17 Replies
google "html input numbers only"
that's not really usefull i tried to find somehting but none of the solutions are really "working" or are not applicable with Solid js
But inputs have nothing to do with solid. They're HTML elements.
the quesiton wa smaybe not correctly said. It's more about using solid in an way to enforce an input field only taking in numerical types nothing else that's not possible in plain html
yes it is.
MDN Web Docs
- HTML: HyperText Markup Language | MDN
elements of type number are used to let the user enter a number. They include built-in validation to reject non-numerical entries.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
NO THIS IS NOT WHAT I MEAN.
I have seen tese docs times before, i try to have an input box whihc ONLY allows numerical values which are valid for type conversation, i appreciate the help but it's not what i am looking for , sitll thanks
look at the playground I sent. You can't type letters into it. (well except e, because 1.2e6 is valid)
you might be looking for https://primitives.solidjs.community/package/input-mask
i never used it myself tho
it has support for a lot more complex input masks, so it's mb a bit of overkill
the
type="number"
is enough for chromebut not on safari
any vanilla js solution should work for solid-js too, so maybe you can find a simpler alternative then the input mask
something like this is how i would do it: https://playground.solidjs.com/anonymous/494dce82-6cf3-47ea-aefb-4f9711fe3cd0
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
thanks, mate.
This is more what i was looking a lot of the vanilla solution i found where a bit more over kill than this
ur welcome!