Javascript

연속된 문자, 숫자 체크(3자리) 함

주원만쉐 2023. 12. 13. 13:27
728x90
/*-
* 연속된 문자, 숫자 체크(3자리)
* */
function isContinuedValue(pw){
    var cnt = 0;
    var cnt2 = 0;
    var tmp = "";
    var tmp2 = "";
    var tmp3 = "";
    for(i=0; i<pw.length; i++){
        tmp = pw.charAt(i);
        tmp2 = pw.charAt(i+1);
        tmp3 = pw.charAt(i+2);
     
        if(tmp.charCodeAt(0) - tmp2.charCodeAt(0) == 1 && tmp2.charCodeAt(0) - tmp3.charCodeAt(0) == 1){
            cnt = cnt + 1;
        }
        if(tmp.charCodeAt(0) - tmp2.charCodeAt(0) == -1 && tmp2.charCodeAt(0) - tmp3.charCodeAt(0) == -1){
            cnt2 = cnt2 + 1;
        }
    }
    if(cnt > 0 || cnt2 > 0){
        return true;
    }else{
        return false;
    }
}
728x90