Jquery validation custom rule input greather than

I am using the jquery validation plugin for khung validation. Using the min property works fine, but I want it lớn validate values strictly greater than that min value.

Bạn đang xem: Jquery validation custom rule input greather than

rules: price: required: true, min: 13, number: true In my code I have min: 13, but I don"t want to allow 13, only values greater than 13, e.g. 13.10, 13.đôi mươi, 14. How can I bởi this?

Thanks in advance !



Create your own custom method with $.validator.addMethod:

$.validator.addMethod("minStrict", function (value, el, param) return value > param;);Then use:

price: required: true, minStrict: 13, number: trueNote: The creators of the validator plugin recommkết thúc adding Number.MIN_VALUE khổng lồ the value you supply:

min: 13 + Number.MIN_VALUENumber.MIN_VALUE is the smallest positive sầu (non-zero) float that JS can handle, hence the ngắn gọn xúc tích is that the two statements below are equivalent:

a > b;a >= b + Number.MIN_VALUE;But, this doesn"t work, due to the way floating-point numbers are stored in memory. Rounding will cause b + Number.MIN_VALUE to lớn equal b in most cases (b must be very small for this lớn work).

Improve this answer
edited Jun 10 "11 at 6:30
answered Jun 10 "11 at 6:05

David TangDavid Tang
85.8k2828 gold badges157157 silver badges144144 bronze badges
Add a bình luận |
min: 13.01, this:

rules: price: required: true, min: 13.01, number: true

Improve sầu this answer
edited Sep 11 "17 at 20:16
answered Sep 11 "17 at 20:03

Daniel Miloca - BrazilDaniel Miloca - Brazil
10711 silver badge44 bronze badges
Add a bình luận |

Your Answer

Thanks for contributing an answer to Staông chồng Overflow!

Please be sure to lớn answer the question. Provide details & share your research!

But avoid

Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; bachồng them up with references or personal experience.

Xem thêm: Ví Dụ Mvc Trong Php - Lập Trình Php Theo Mô Hình Mvc

To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using E-Mail và Password

Post as a guest

E-Mail Required, but never shown

Post as a guest


Required, but never shown

Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy

Not the answer you're looking for? Browse other questions tagged jquery jquery-validate or ask your own question.

The Overflow Blog
Featured on Meta
Visit chat
Dynamic jQuery Validate error messages with AddMethod based on the element
jQuery Validate Custom Function - More than Minimum Value
Is there an “exists” function for jQuery?
Add table row in jQuery
How bởi vì I kiểm tra if an element is hidden in jQuery?
Setting “checked” for a checkbox with jQuery
How vày I kiểm tra whether a checkbox is checked in jQuery?
Disable/enable an input đầu vào with jQuery?
jQuery Validate Required Select
How can I refresh a page with jQuery?
jQuery scroll khổng lồ element
Hot Network Questions more hot questions

Question feed
Subscribe lớn RSS
Question feed To subscribe to this RSS feed, copy and paste this URL inkhổng lồ your RSS reader.


Stachồng Overflow
Staông chồng Exchange Network
site design / hình ảnh sản phẩm © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.5.38726