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