Reeebuuk1

by SmokeyPHP

JavaScript

function isValid(str)
{
    var m = str.match(/(?:^|, ?)([a-z])((?!\1)[a-z])\d/ig); //Find correctly formatted pieces
    return m && m.length == str.split(/ ?, ?/).length; //Check the amount of correct pieces against the amount of pieces between " , "
}

var s1 = 'AB5,CB12, LB1,SS8'; // invalid
var s2 = 'CA5,CB12, LB1,ST8'; // valid
var s3 = 'AB5,CB12, LB1,,ST8'; // invalid
console.log(isValid(s1),isValid(s2),isValid(s3)); // false true false