How to validate decimal number with random value from input box using jQuery?
I have sample code below:
$("#actualWeight").on('keyup', function(e) {
if (e.keyCode == 13) {
var actualWeight = $("#actualWeight").val();
var maxGrossWeight = "3.6";
var minGrossWeight = "2.4";
if (actualWeight > maxGrossWeight) {
alert("More than max gross");
} else if (actualWeight < minGrossWeight) {
alert("Lower than min gross");
} else {
alert("Success");
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input type="text" id="actualWeight" />
As you can see:
Min Gross = 2.4
Max Gross = 3.6
When I try to input 200, it show me alert Success that should be show me alert More than max gross.
You can see it on this fiddle