Maska даты проверка на ввод

by AJIEKCEU

HTML

<input type="text" class="it" name="it-date" placeholder="дд.мм.гггг"/>

<div id="error-it-date">?</div>

JavaScript

var input = jQuery('.it');
jQuery(input).bind('keyup change', function()
    {
    var error = false;

    var value = $(this).val().split('.');
    if (value.length != 3 || !(value[0] && value[1] && value[2].length == 4))
        {
        error = 'Invalid value';
        }
    else
        {
        var date = new Date(value[2] + '-' + value[1] + '-' + value[0]);
    
        if (isNaN(date.getTime()))
            error = 'Invalid date';
        else if (parseInt(value[0]) != date.getDate())
            error = 'Unexpected day of month';
        else if (parseInt(value[1]) != date.getMonth() + 1)
            error = 'Unexpected month';
        else
            {
            var rValueYear = value[2].toString().split('').reverse().join('');
            var rDateYear = date.getFullYear().toString().split('').reverse().join('');
            if (rValueYear.length > rDateYear.length || rDateYear.indexOf(rValueYear) !== 0)
                error = 'Ambiguous year';
            }
        }

    if (error)
        {
        $('#error-' + (this.id || this.name)).text(error);
        //return false;
        }
    else
        {
        $('#error-' + (this.id || this.name)).text('Okay');
        return true;
        }
    });


/**
 * @see http://github.com/NV/placeholder.js
 */
jQuery.fn.textPlaceholder = function () {

	return this.each(function(){

		var that = this;

		if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;

		var placeholder = that.getAttribute('placeholder');
		var input = jQuery(that);

		if (that.value === '' || that.value == placeholder) {
			input.addClass('text-placeholder');
			that.value = placeholder;
		}

		input.focus(function(){
			if (input.hasClass('text-placeholder')) {
				this.value = '';
				input.removeClass('text-placeholder')
			}
		});

		input.blur(function(){
			if (this.value === '') {
				input.addClass('text-placeholder');
				this.value = placeholder;
			} else...