Skip to content

Instantly share code, notes, and snippets.

@honbin
Created June 22, 2012 10:45
Show Gist options
  • Save honbin/2972021 to your computer and use it in GitHub Desktop.
Save honbin/2972021 to your computer and use it in GitHub Desktop.
ajaxzipの引数thisをディープコピーしてvalueの値を半角数値にして返す
(function($) {
convertHalfwidthNum = function(obj) {
var cObj = $.extend(true, {}, obj);
var str = '';
var v = cObj.value;
var len = v.length;
for (var i = 0; i < len; i++) {
var c = v.charCodeAt(i);
if ((c >= 65296 && c <= 65305))
str += String.fromCharCode(c - 65248);
else if(v.charAt(i).match(/\d+/g))
str += v.charAt(i);
}
cObj.value = str;
return cObj;
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment