开发者

Number & Decimal Validations using Jquery

开发者 https://www.devze.com 2023-01-29 04:26 出处:网络
I need to implement following validations.Please suggest any jQuery plugin for this. Case -1 Numeric N开发者_运维百科umber Range : (0-9999)

I need to implement following validations.Please suggest any jQuery plugin for this.

Case -1

Numeric N开发者_运维百科umber Range : (0-9999) Non Negative Non Decimal

Case -2

Numeric Number Range : (0-99.99) Non Negative Decimal with more than 2 digits after decimal is not allowed

Case -3

Numeric Number Range : (0-99999) Non Negative Decimal @ first position or last position


You can use the jQuery validation plugin

http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js
http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js
http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js
http://ajax.microsoft.com/ajax/jquery.validate/1.7/additional-methods.js

The demos are available at http://docs.jquery.com/Plugins/validation


better use server side validations, javascript validations are client-side and can be hacked easily

Edit: using the jQuery validation plugin

$("#myform").validate({
  rules: {
    field: {
      required: true,
      range: [0,9999]
    }
  }
});

The second case is a bit strange, are you passing strings to the database? try with

number: true
max: 99.99
min: 0
0

精彩评论

暂无评论...
验证码 换一张
取 消