Created
April 22, 2015 01:00
-
-
Save RyoSugimoto/7a5a45d9660b180d2af7 to your computer and use it in GitHub Desktop.
全角の英数文字を半角文字に変換する。
This file contains hidden or 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 toAN = function (data) { | |
var dataType = typeof data, | |
str = String(data); | |
str = str.replace(/[A-Za-z0-9]/g, function(s) { | |
return String.fromCharCode(s.charCodeAt(0) - 65248); | |
}); | |
return dataType == 'number' ? Number(str) : str; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment