var inputs=document.querySelectorAll('.bel'); var validity = [].every.call(inputs, function(node) { var str = node.value.trim() return /^(C|M|X)/.test(str) }); if(validity) alert("ok");