Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check consecutive characters in javascript

var password = '5236aaa121';

for(var i = 0; i< password.length; i++) {
    var numberOfRepeats = CheckForRepeat(i, password, password.charAt(i));
    //do something

}

function CheckForRepeat(startIndex, originalString, charToCheck) {
    var repeatCount = 1;
    for(var i = startIndex+1; i< password.length; i++) {
        if(originalString.charAt(i) == charToCheck) {
            repeatCount++;
        } else {
        return repeatCount;
        }   
    }
    return repeatCount;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #consecutive #characters #javascript
ADD COMMENT
Topic
Name
7+5 =