Код: Выделить всё
/^(?:[A-Z0-9]{1,3}(?:, |,)?)*$/
< /code>
, который, к сожалению, позволяет вводу, как «Brualc» < /p>
Я решил его с дополнительной проверкой времени выполнения: < /p>
function isValid(input) {
const format = /^(?:[A-Z0-9]{1,3}(?:, |,)?)*$/;
if (!format.test(input)) return false;
// Split the words and validate each
const words = input
.split(/, ?/)
.filter(w => w.length > 0); // skip empty trailing entries
return words.every(w => /^[A-Z0-9]{1,3}$/.test(w));
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... nd-space-a