Last active
August 29, 2015 14:14
-
-
Save Langmans/a32532777c167e275896 to your computer and use it in GitHub Desktop.
input type checking (datetime, email, etc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function ($) { | |
if (!inputsupport('datetime-local')) { | |
$('[type=datetime-local]').each(function () { | |
var $input = $(this), placeholder = $input.attr('placeholder'); | |
$input.attr({ | |
type: 'text', | |
placeholder: this.hasAttribute('placeholder') ? placeholder + ' (JJJJ-MM-DD UU:MM)' : 'JJJJ-MM-DD UU:MM', | |
pattern: '20\\d{2}(-|\/)((0[1-9])|(1[0-2]))(-|\/)((0[1-9])|([1-2][0-9])|(3[0-1]))(T|\\s)(([0-1][0-9])|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))?' | |
}); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inputsupport = (function () { | |
// private variables. | |
var support = {}, input; | |
// the actual check. | |
return function (type) { | |
if (!support.hasOwnProperty(type)) { | |
input = input || document.createElement('input'); | |
input.type = type; | |
// input.type is set back to text if not supported, | |
// so we can just compare the type parameter with the input type property/attribute. | |
support[type] = input.type == type; | |
} | |
return support[type]; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment