This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//const pattern = 'XXXXXXXXXXXXIIXXXX' | |
const digitsRe = new RegExp('/^\d+$/') | |
function test(str) { | |
if (str.length == 0) return false | |
// part 1: check that first at most 12 characters are only numbers | |
let end = Math.min(12, str.length) | |
if !digitsRe.test(str.substring(0, end)) return false | |
// part 3: check that at most 4 characters after 12 digits and 2 any chars are only numbers | |
end = Math.min(12 + 2 + 4, str.length) |
OlderNewer