##JavaScript (ES6), 71 bytes <!-- language: lang-js --> f=([a,...b])=>a?(+a&(a+=b[0])+b[1]<123|a>47&a<58|a>64&a<91|a>96)+f(b):0 ###Test cases <!-- begin snippet: js hide: true console: true babel: false --> <!-- language: lang-js --> f=([a,...b])=>a?(+a&(a+=b[0])+b[1]<123|a>47&a<58|a>64&a<91|a>96)+f(b):0 console.log(f("5698")) // 3 console.log(f("564693")) // 2 console.log(f("530923864209124521")) // 3 console.log(f("1111111")) // 5 console.log(f("5115643141276343")) // 4 console.log(f("56789")) // 4 console.log(f("94")) // 0 console.log(f("1")) // 0 <!-- end snippet -->