限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery表单日期分隔切割输入实时验证插件

所属分类: 网页特效-表单验证    2023-11-06 12:34:21

jquery表单日期分隔切割输入实时验证插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery表单日期分隔切割输入实时验证插件(共28个文件)

    • jquery.datetextentry.js
    • jquery.datetextentry.css
    • jquery.datetextentry.css
    • README.md
    • index.html
    • index.html

使用方法

  • code
  • source
  1. (function ($) {
  2. 'use strict';
  3. /* CUSTOM ERROR CLASS
  4. * ================== */
  5. var DateValidationError = function (message, source_input) {
  6. this.message = message;
  7. this.source_input = source_input; // Might be undefined
  8. };
  9. DateValidationError.prototype = Error.prototype;
  10. /* DATETEXTENTRY CLASS DEFINITION
  11. * ============================== */
  12. var days_in_month = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
  13. var key = { BACKSPACE : 8 };
  14. var DateTextEntry = function (element, options) {
  15. this.$element = $(element);
  16. this.options = $.extend({}, $.fn.datetextentry.defaults, options);
  17. this.add_century = this.options.add_century || this.add_century;
  18. this.parse_date = this.options.parse_date || this.parse_date;
  19. this.format_date = this.options.format_date || this.format_date;
  20. this.human_format_date = this.options.human_format_date || this.human_format_date;
  21. this.on_blur = this.options.on_blur;
  22. this.on_change = this.options.on_change;
  23. this.on_error = this.options.on_error;
  24. this.custom_validation = this.options.custom_validation;
  25. this.build_ui();
  26. this.set_date(this.$element.attr('value'));
  27. this.proxy_label_clicks();
  28. };
  29. function str_right(str, n) { return str.substr(str.length - n); }
  30. function pad2(n) { return str_right('00' + (n || 0), 2); }
  31. function pad4(n) { return str_right('0000' + (n || 0), 4); }
  32. DateTextEntry.prototype = {
  33. constructor: DateTextEntry,
  34. build_ui: function () {
  35. var dte = this;
  36. this.wrapper = $(this.$element.wrap('<span class="jq-dte" />').parent()[0]);
  37. this.inner = $('<span class="jq-dte-inner" />');
  38. this.add_entry_fields();
  39. this.tooltip = $('<span class="jq-dte-tooltip" />').hide();
  40. this.errorbox = $('<span class="jq-dte-errorbox" />').hide();
  41. this.inner.on('paste', 'input', function (e) {
  42. var input = this;
  43. setTimeout(function () { dte.after_paste(input, e); }, 2);
  44. });
  45. this.wrapper.append(this.inner, this.tooltip, this.errorbox);
  46. this.set_field_widths();
  47. this.$element.hide();
  48. },
  49. add_entry_fields: function () {
  50. var dte = this;
  51. dte.fields = [];
  52. $.each(this.options.field_order.split(''), function (i, field) {
  53. switch (field) {
  54. case 'D':
  55. dte.build_field('day', i);
  56. break;
  57. case 'M':
  58. dte.build_field('month', i);
  59. break;
  60. case 'Y':
  61. dte.build_field('year', i);
  62. break;
  63. default :
  64. throw new Error("Unexpected field order '" + field + "' expected D, M or Y");
  65. }
  66. });
  67. },
  68. build_field: function (name, index) {
  69. var dte = this;
  70. var opt = this.options;
  71. var input = new DateTextInput({
  72. name : name,
  73. dte : dte,
  74. index : index,
  75. hint_text : opt.show_hints ? opt['field_hint_text_' + name] : null,
  76. tip_text : opt['field_tip_text_' + name],
  77. auto_focus_text : opt['field_auto_focus_' + name]
  78. });
  79. this.inner.append(input.$input);
  80. this['input_' + name] = input;
  81. if (index < 2) {
  82. this.inner.append($('<span class="separator" />').text(opt.separator));
  83. }
  84. this.fields[index] = input;
  85. this[name] = input;
  86. },
  87. set_field_widths: function () {
  88. var opt = this.options;
  89. var available = this.$element.width() - 2;
  90. var total = opt.field_width_year + opt.field_width_sep + opt.field_width_month +
  91. opt.field_width_sep + opt.field_width_day;
  92. this.input_day.set_width(Math.floor(opt.field_width_day * available / total));
  93. this.input_month.set_width(Math.floor(opt.field_width_month * available / total));
  94. this.input_year.set_width(Math.floor(opt.field_width_year * available / total));
  95. },
  96. set_date: function (new_date) {
  97. var dte = this;
  98. new_date = this.parse_date(new_date);
  99. delete this.day_value;
  100. delete this.month_value;
  101. delete this.year_value;
  102. this.input_day.set(new_date ? new_date.day : '');
  103. this.input_month.set(new_date ? new_date.month : '');
  104. this.input_year.set(new_date ? new_date.year : '');
  105. this.clear_error();
  106. this.$element.val(new_date);
  107. if (new_date) {
  108. $.each(this.fields, function (i, input) {
  109. dte.validate(input);
  110. });
  111. }
  112. },
  113. proxy_label_clicks: function () {
  114. var dte = this;
  115. var id = this.$element.attr('id');
  116. if (!id) { return; }
  117. $('label[for=' + id + ']').click(function () {
  118. dte.focus();
  119. });
  120. },
  121. clear: function () {
  122. this.clear_error('');
  123. this.set_date('');
  124. },
  125. destroy: function () {
  126. this.$element.show();
  127. this.$element.css('display', '');
  128. this.wrapper.find('span').remove();
  129. this.$element.unwrap();
  130. this.$element.removeData('datetextentry');
  131. delete this.inner;
  132. delete this.wrapper;
  133. delete this.$element;
  134. },
  135. after_paste: function (target) {
  136. var date = $(target).val();
  137. if (this.parse_date(date)) {
  138. this.set_date(date);
  139. }
  140. },
  141. parse_date: function (text) {
  142. return this.parse_iso_date(text);
  143. },
  144. parse_iso_date: function (text) {
  145. return text && text.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)
  146. ? { day: RegExp.$3, month: RegExp.$2, year: RegExp.$1 }
  147. : null;
  148. },
  149. get_date : function () {
  150. return (this.day_value && this.month_value && this.year_value)
  151. ? { day: this.day_value, month: this.month_value, year: this.year_value }
  152. : null;
  153. },
  154. get_today : function () {
  155. var today = new Date();
  156. return {
  157. day: pad2(today.getDate()),
  158. month: pad2(today.getMonth() + 1),
  159. year: pad4(today.getFullYear())
  160. };
  161. },
  162. format_date : function (date) {
  163. return this.iso_format_date(date);
  164. },
  165. iso_format_date : function (date) {
  166. return [ pad4(date.year), pad2(date.month), pad2(date.day) ].join('-');
  167. },
  168. human_format_date: function (date) {
  169. return [ pad2(date.day), pad2(date.month), pad4(date.year) ].join('/');
  170. },
  171. add_century: function (year) {
  172. return 2000 + year;
  173. },
  174. focus_in: function () {
  175. this.wrapper.addClass('focus');
  176. },
  177. focus_out: function () {
  178. if (this.on_blur || this.options.is_required) {
  179. var self = this;
  180. setTimeout(function () { self.check_widget_focus_lost(); }, 2);
  181. }
  182. this.wrapper.removeClass('focus');
  183. },
  184. check_widget_focus_lost: function () {
  185. var opt = this.options;
  186. if (this.wrapper.is('.focus')) {
  187. return;
  188. }
  189. if (opt.is_required) {
  190. if (!this.get_date()) {
  191. this.set_error(opt.E_REQUIRED_FIELD);
  192. }
  193. }
  194. if (this.on_blur) {
  195. this.on_blur();
  196. }
  197. },
  198. show_input_tip: function (input) {
  199. var opt = this.options;
  200. if (!opt.show_tooltips) { return; }
  201. var x_offset = (input.left() + opt.tooltip_x) + 'px';
  202. var y_offset = (this.wrapper.height() + opt.tooltip_y) + 'px';
  203. this.tooltip.css({position: 'absolute', top: y_offset, left: x_offset})
  204. .text(input.tip_text)
  205. .show();
  206. },
  207. hide_input_tip: function () {
  208. this.tooltip.hide();
  209. },
  210. set_error: function (error_text, source_input) {
  211. this.error_text = error_text;
  212. this.error_source_input = source_input;
  213. this.show_error();
  214. },
  215. clear_error: function () {
  216. delete this.error_text;
  217. this.show_error();
  218. },
  219. set_readonly: function (mode) {
  220. if (mode === undefined) {
  221. mode = true;
  222. }
  223. this.input_day.set_readonly(mode);
  224. this.input_month.set_readonly(mode);
  225. this.input_year.set_readonly(mode);
  226. if (mode) {
  227. this.wrapper.addClass('readonly');
  228. }
  229. else {
  230. this.wrapper.removeClass('readonly');
  231. }
  232. },
  233. show_error: function () {
  234. var opt = this.options;
  235. var error_text = this.widget_error_text();
  236. if (this.on_error) {
  237. this.on_error(error_text);
  238. }
  239. if (!opt.show_errors) {
  240. return;
  241. }
  242. if (error_text === '') {
  243. this.errorbox.hide();
  244. this.errorbox.text('');
  245. }
  246. else {
  247. var x_offset = (this.inner.outerWidth() + o<p></p>
(function ($) {

    'use strict';


    /* CUSTOM ERROR CLASS
     * ================== */

    var DateValidationError = function (message, source_input) {
        this.message = message;
        this.source_input = source_input;  // Might be undefined
    };

    DateValidationError.prototype = Error.prototype;


    /* DATETEXTENTRY CLASS DEFINITION
     * ============================== */

    var days_in_month = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
    var key = { BACKSPACE : 8 };

    var DateTextEntry = function (element, options) {
        this.$element          = $(element);
        this.options           = $.extend({}, $.fn.datetextentry.defaults, options);
        this.add_century       = this.options.add_century       || this.add_century;
        this.parse_date        = this.options.parse_date        || this.parse_date;
        this.format_date       = this.options.format_date       || this.format_date;
        this.human_format_date = this.options.human_format_date || this.human_format_date;
        this.on_blur           = this.options.on_blur;
        this.on_change         = this.options.on_change;
        this.on_error          = this.options.on_error;
        this.custom_validation = this.options.custom_validation;
        this.build_ui();
        this.set_date(this.$element.attr('value'));
        this.proxy_label_clicks();
    };

    function str_right(str, n) { return str.substr(str.length - n); }
    function pad2(n) { return str_right('00'   + (n || 0), 2); }
    function pad4(n) { return str_right('0000' + (n || 0), 4); }

    DateTextEntry.prototype = {

        constructor: DateTextEntry,

        build_ui: function () {
            var dte = this;
            this.wrapper = $(this.$element.wrap('<span class="jq-dte" />').parent()[0]);
            this.inner   = $('<span class="jq-dte-inner" />');
            this.add_entry_fields();
            this.tooltip  = $('<span class="jq-dte-tooltip" />').hide();
            this.errorbox = $('<span class="jq-dte-errorbox" />').hide();
            this.inner.on('paste', 'input', function (e) {
                var input = this;
                setTimeout(function () { dte.after_paste(input, e); }, 2);
            });
            this.wrapper.append(this.inner, this.tooltip, this.errorbox);
            this.set_field_widths();
            this.$element.hide();
        },

        add_entry_fields: function () {
            var dte = this;
            dte.fields = [];
            $.each(this.options.field_order.split(''), function (i, field) {
                switch (field) {
                case 'D':
                    dte.build_field('day',   i);
                    break;
                case 'M':
                    dte.build_field('month', i);
                    break;
                case 'Y':
                    dte.build_field('year',  i);
                    break;
                default :
                    throw new Error("Unexpected field order '" + field + "' expected D, M or Y");
                }
            });
        },

        build_field: function (name, index) {
            var dte   = this;
            var opt   = this.options;
            var input = new DateTextInput({
                name            : name,
                dte             : dte,
                index           : index,
                hint_text       : opt.show_hints ? opt['field_hint_text_' + name] : null,
                tip_text        : opt['field_tip_text_'  + name],
                auto_focus_text : opt['field_auto_focus_' + name]
            });
            this.inner.append(input.$input);
            this['input_' + name] = input;

            if (index < 2) {
                this.inner.append($('<span class="separator" />').text(opt.separator));
            }

            this.fields[index] = input;
            this[name] = input;
        },

        set_field_widths: function () {
            var opt       = this.options;
            var available = this.$element.width() - 2;
            var total     = opt.field_width_year + opt.field_width_sep + opt.field_width_month +
                opt.field_width_sep + opt.field_width_day;
            this.input_day.set_width(Math.floor(opt.field_width_day     * available / total));
            this.input_month.set_width(Math.floor(opt.field_width_month * available / total));
            this.input_year.set_width(Math.floor(opt.field_width_year   * available / total));

        },

        set_date: function (new_date) {
            var dte = this;
            new_date = this.parse_date(new_date);
            delete this.day_value;
            delete this.month_value;
            delete this.year_value;
            this.input_day.set(new_date   ? new_date.day   : '');
            this.input_month.set(new_date ? new_date.month : '');
            this.input_year.set(new_date  ? new_date.year  : '');
            this.clear_error();
            this.$element.val(new_date);
            if (new_date) {
                $.each(this.fields, function (i, input) {
                    dte.validate(input);
                });
            }
        },

        proxy_label_clicks: function () {
            var dte = this;
            var id  = this.$element.attr('id');
            if (!id) { return; }
            $('label[for=' + id + ']').click(function () {
                dte.focus();
            });
        },

        clear: function () {
            this.clear_error('');
            this.set_date('');
        },

        destroy: function () {
            this.$element.show();
            this.$element.css('display', '');
            this.wrapper.find('span').remove();
            this.$element.unwrap();
            this.$element.removeData('datetextentry');
            delete this.inner;
            delete this.wrapper;
            delete this.$element;
        },

        after_paste: function (target) {
            var date = $(target).val();
            if (this.parse_date(date)) {
                this.set_date(date);
            }
        },

        parse_date: function (text) {
            return this.parse_iso_date(text);
        },

        parse_iso_date: function (text) {
            return text && text.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)
                ? { day: RegExp.$3, month: RegExp.$2, year: RegExp.$1 }
                : null;
        },

        get_date : function () {
            return (this.day_value && this.month_value && this.year_value)
                ? { day: this.day_value, month: this.month_value, year: this.year_value }
                : null;
        },

        get_today : function () {
            var today = new Date();
            return {
                day:   pad2(today.getDate()),
                month: pad2(today.getMonth() + 1),
                year:  pad4(today.getFullYear())
            };
        },

        format_date : function (date) {
            return this.iso_format_date(date);
        },

        iso_format_date : function (date) {
            return [ pad4(date.year), pad2(date.month), pad2(date.day) ].join('-');
        },

        human_format_date: function (date) {
            return [ pad2(date.day), pad2(date.month), pad4(date.year) ].join('/');
        },

        add_century: function (year) {
            return 2000 + year;
        },

        focus_in: function () {
            this.wrapper.addClass('focus');
        },

        focus_out: function () {
            if (this.on_blur || this.options.is_required) {
                var self = this;
                setTimeout(function () { self.check_widget_focus_lost(); }, 2);
            }
            this.wrapper.removeClass('focus');
        },

        check_widget_focus_lost: function () {
            var opt = this.options;
            if (this.wrapper.is('.focus')) {
                return;
            }
            if (opt.is_required) {
                if (!this.get_date()) {
                    this.set_error(opt.E_REQUIRED_FIELD);
                }
            }
            if (this.on_blur) {
                this.on_blur();
            }
        },

        show_input_tip: function (input) {
            var opt = this.options;
            if (!opt.show_tooltips) { return; }
            var x_offset = (input.left() + opt.tooltip_x) + 'px';
            var y_offset = (this.wrapper.height() + opt.tooltip_y) + 'px';
            this.tooltip.css({position: 'absolute', top: y_offset, left: x_offset})
                .text(input.tip_text)
                .show();
        },

        hide_input_tip: function () {
            this.tooltip.hide();
        },

        set_error: function (error_text, source_input) {
            this.error_text = error_text;
            this.error_source_input = source_input;
            this.show_error();
        },

        clear_error: function () {
            delete this.error_text;
            this.show_error();
        },

        set_readonly: function (mode) {
            if (mode === undefined) {
                mode = true;
            }
            this.input_day.set_readonly(mode);
            this.input_month.set_readonly(mode);
            this.input_year.set_readonly(mode);
            if (mode) {
                this.wrapper.addClass('readonly');
            }
            else {
                this.wrapper.removeClass('readonly');
            }
        },

        show_error: function () {
            var opt = this.options;
            var error_text = this.widget_error_text();
            if (this.on_error) {
                this.on_error(error_text);
            }
            if (!opt.show_errors) {
                return;
            }
            if (error_text === '') {
                this.errorbox.hide();
                this.errorbox.text('');
            }
            else {
                var x_offset = (this.inner.outerWidth() + o<p></p>
                                                
站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 表单验证

jquery会员注册表单验证

一款基于jquery多类型表单验证,包含了表单验证、生日下拉框选择、邮箱自动补全、密码可见性与重复密码的验证等,非常实用。
  表单验证
 5314  0

jquery自定义文本文字传递到DIV并显示插件

一款onclick时间传递文本内容到指定DIV元素显示,非常的高效实用。
  表单验证
 4397  0

js表单输入密码在线检验插件

一款密码实时检查插件,根据即时输入的密码进行实时反馈,检查所输入的字符是否包含有特定字符。
  表单验证
 9266  0

原生js实现的支持移动端触屏拼图滑块验证插件

一款支持移动端触摸滑块验证插件,随机加载不同的背景图片,然后在背景图片上增加拼图滑块,手动拖动水平滑块即可验证。
  表单验证
 5234  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论