I am writing a (localhost) website that is planned to be used in the Opera browser (since my site is using HTML5). In part of the site I have a form and one of the fields is a number. I am trying to use jQuery Validate plugin to validate that the entry is a number, but it is NOT required.
Example of code for validation of input type=number works, but using required:
- <form id="productForm">
- <input type="number" name="MinPrice" id="Minprice" />
- <input type="submit" value="OK" />
- </form>
- $("#productForm").validate({
- rules: {
- MinPrice: {
- number: true,
- required: true
- }
- }
- });
I expected this code example to work because I do not require a number to have a value, just to validate if I inserted a number:
- <form id="productForm">
- <input type="number" name="MinPrice" id="Minprice" />
- <input type="submit" value="OK" />
- </form>
- $("#productForm").validate({
- rules: {
- MinPrice: {
- number: true
- }
- }
- });
If the input type was text instead of number, I am able to validate the field as a number without it being required, like this example:
- <form id="productForm">
- <input type="text" name="MinPrice" id="Minprice" />
- <input type="submit" value="OK" />
- </form>
- $("#productForm").validate({
- rules: {
- MinPrice: {
- number: true
- }
- }
- });
Thank you,
CampSoup1988