Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created April 22, 2015 01:00
Show Gist options
  • Save RyoSugimoto/7a5a45d9660b180d2af7 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/7a5a45d9660b180d2af7 to your computer and use it in GitHub Desktop.
全角の英数文字を半角文字に変換する。
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