Skip to content

Instantly share code, notes, and snippets.

@ksk1015
Created December 9, 2016 09:42
Show Gist options
  • Save ksk1015/0ed7eb1f67503577f9619fb88ef4e2da to your computer and use it in GitHub Desktop.
Save ksk1015/0ed7eb1f67503577f9619fb88ef4e2da to your computer and use it in GitHub Desktop.
data-hansu属性のinputを強制的に半数字のみに変換
document.addEventListener('change', function(evt){
var elem = evt.target;
if ( elem.hasAttribute('data-hansu') ) {
elem.value = elem.value.replace(/[0-9]/g, function(s){
return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
}).replace(/\D/g, '');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment