开发者

Custom jQuery validation plugin

开发者 https://www.devze.com 2023-01-13 12:01 出处:网络
My boss asked me to program a custom jQuery validation plugin. If <input /> taghas special attribute [needcheck], my plugin must determine the type of [needcheck] andcheck input data before subm

My boss asked me to program a custom jQuery validation plugin. If <input /> tag has special attribute [needcheck], my plugin must determine the type of [needcheck] and check input data before submit.

For example:

<input name="email" type="text" needchek=”Email”/>

If value of <input /> tag has errors, plugin must show a promting message.

Available types for [needcheck]:

  • Date:[FORMATDATE] – date in format (For example Date:dd.MM.yyyy)
  • Time:[TIMEFORMAT开发者_运维知识库] – time in format (for example Time:HH:MM:SS)
  • INT – integer number
  • Decimal:[DECIMALFORMAT] – Decimal number
  • Email – email address
  • Etc.

The code:

(function($) { 
    $.fn.somePlugin = function(options) { 
        var defaults = { 
            someOption: 'someValue'
        }; 
        var opts = $.extend(defaults, options); 
    };   
})(jQuery);


I think you could use the jQuery plugin validity as it is flexible enough for almost anything, because you can give it an assert or callback as a validation rule: Assert Demo

0

精彩评论

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

关注公众号