요구사항 숫자 전각을 반각으로 인식 문제점 일본어는 전각, 반각이 있다. 반각은 1byte, 전각은 2byte byte체크하는 함수를 만들었을 때.. 오류가 발생! JS - 전각 숫자를 반각 숫자로 변경 String.prototype.toHalfWidth = function(){ return this.replace(/[!-~]/g, function(r){ // replace의 정규식은 요구사항에 맞추어 변경가능 return String.fromCharCode(r.charCodeAt(0) - 0xFEE0); }); }; var result = '000'.toHalfWidth(); console.log(result); // 000 - 숫자외에 입력 불가 result = result.replace(/\s|\D..
Javascript
2018. 9. 28. 18:33