I want to get only positive values, is there any way to prevent it using only html
Please don't suggest validation method
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
For me the solution was:
The @Manwal answer is good, but i like code with less lines of code for better readability. Also i like to use onclick/onkeypress usage in html instead.
My suggested solution does the same: Add
to the html input and
as a javascript function.
As said, it does the same. It's just personal preference on how to solve the problem.
Just for reference: with jQuery you can overwrite negative values on focusout with the following code:
This does not replace server side validation!
I wanted to allow decimal numbers and not clear the entire input if a negative was inputted. This works well in chrome at least:
Use the
min
attribute like this: