+ 1

Restriction of input type

Hello everyone! Please, could you provide a solution to the restriction of input? For example, "only digits" would make no effect on the input box if key pressed other than digit or vice versa with text (characters). Thanks in advance!

7th Aug 2020, 1:33 PM
Kekit
4 Réponses
+ 5
Kekit Kind of, but not entirely true. There's also 'email', 'tel' and 'url' for e-mail phone number and URL, respectively. But value of input 'type' attribute only helps by means of displaying relevant optional button on the keyboard, depending on attribute value. For example the @ button is shown for 'email' or 'www' button shown for 'url' input. Yet again, it does not enforce restriction, thus obviously, validation is still in order. https://www.w3schools.com/html/html_form_input_types.asp
7th Aug 2020, 2:16 PM
Ipang
+ 3
Not exactly sure what you wanted, but as I understand it <input type="number" /> allows digits and formatting characters e.g. decimal point, no alphabet nor others. I'd suggest you to add more info on what it is you actually are looking into.
7th Aug 2020, 1:40 PM
Ipang
+ 3
For Java You can't, because that's how SoloLearn code playground works. Instead, you need to add scripts in your code to validate user input. For JavaScript, you can specify input type.
7th Aug 2020, 2:01 PM
Gordon
Gordon - avatar
+ 2
Ipang I suppose that this is answer to me)) 'type=' attribute of input restricts user from using other than 'type'. Correct?
7th Aug 2020, 2:06 PM
Kekit