Created
December 9, 2016 09:42
-
-
Save ksk1015/0ed7eb1f67503577f9619fb88ef4e2da to your computer and use it in GitHub Desktop.
data-hansu属性のinputを強制的に半数字のみに変換
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
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