Knowledge Map

문자열 숫자 변환, 특정 문자열만 들어잇는지를 확인 본문

WEB/JAVASCRIPT

문자열 숫자 변환, 특정 문자열만 들어잇는지를 확인

2016. 11. 6. 13:10


var test = "abcd"
console.log ( test.charCodeAt(0) ); // 97
console.log ( test.charCodeAt(3) ); // 100
 
console.log ( String.fromCharCode(97) );   // a
console.log ( String.fromCharCode(100) );  // b
cs


charCodeAt과 fromCharCode를 이용하면 문자 < -- > 숫자 변환이 가능하다.



=================


정규 표현식으로 먼저 특정 문자열만 들어가 있을수 있는 표현식을 짠다.


그다음 test.match(myRe) 이런식으로 짜면 그 정규표현식에 적용되는 문자열이 다 출력이 된다. 그후에 적당히 요리하면 된다.


var checkReg          = /[a-zA-Z0-9#]/g,
    valueLength      = value.length;
var testResultLength = value.match( checkReg ).length;
cs


'WEB > JAVASCRIPT' 카테고리의 다른 글

this를 사용하지 않는 javascript OOP 프로그래밍  (0) 2017.02.01
JS 퀴즈  (0) 2016.11.07
removeEventListener  (0) 2016.11.06
eventlistener, eventhandler 관리  (0) 2016.11.05
on동작이벤트  (0) 2016.11.03
Comments