I have two textboxes (input fields) like following:
<input type="text" class="txtmin" placeholder="Minimum price">
<input type="text" class="txtmax" placeholder="Maximum price">
I'm trying a method like this to prevent the user from entering the following values:
If the user hasn't entered anything in either of these two values, he can proceed.
If the user entered something into txtmin textbox, but hasn't entered anything into the txt max, only txtmin shall be validated
Like 2 but vice versa
2 and 3 validation occurs on following basis:
- If user enters anything besides an integer number or floating point number, error is displayed.
So for example when I enter: 1 or 2.50 or 1.00 this is okay...
Number which has comma in it can't be allowed.
So I've tried it like following:
$(".btnGo").click(function () {
var r = new RegExp("/^[+-]?\d+(\.\d+)?$/");
var min = $('.txtmin').val();
var max =$('.txtmax').val();
if ($('.txtSearch').val() == "") {
ShowMessage("All fields are required");
return;
} else if ($('.txtmin').val() != "") {
if (!r.test(min)) {
ShowMessage("Entry only number for minimum price!");
return;
}
}
else {
PostAndUpdate($('.txtSearch').val(), $('input[name=type]:checked').val(), $('input[name=shipping]:checked').val(), $('input[name=condition]:checked').val(), $('.txtmin').val(), $('.txtmax').val());
}
});
But for example when I don't leave leave the txtmin value empty, I enter:
1.25 <<<
I still get the error for some reason???
Entry only number for minimum price
What am I doing wrong here?