Skip to content

Instantly share code, notes, and snippets.

@rmpel
Created September 6, 2017 12:42
Show Gist options
  • Select an option

  • Save rmpel/1626a90dacc7276b0052d9b6757e636c to your computer and use it in GitHub Desktop.

Select an option

Save rmpel/1626a90dacc7276b0052d9b6757e636c to your computer and use it in GitHub Desktop.
User friendly zip-code input, for DUTCH zip-codes. Gebruikersvriendelijke postcode invoer. (iOS getest)
(function($){
$.fn.input_zip = function(){
return $(this).on('keyup', function(e){
if ($(this).val().length >= 4) {
$(this).attr('inputmode', 'text');
$(this).attr('type', 'text');
}
else {
$(this).attr('inputmode', 'numeric');
$(this).attr('type', 'tel');
}
$(this).blur();
$(this).val( $(this).val().toUpperCase().replace(/[^0-9A-Z]+/, '') );
$(this).focus();
}).trigger('keyup').attr('maxlength', 6);
}
$("input[type=zip]").input_zip();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment