javascript - Regular expression. Find three words in the field -
help make correct regular expression search 3 words field. far have done so, think it's crazy.
var inp = document.getelementsbytagname('input')[0], button = document.getelementsbytagname('button')[0]; button.onclick = function() { console.log(inp.value.match(/^([а-яa-z0-9]+ ){2}[а-яa-z0-9]+/i)); };
<input type="text" /> <button>check</button>
i guess it's easier split text , verify element count expect it. may want trim text before avoid leading , trailing empty strings in result array.
console.log(inp.value.trim().split(/\s+/))
Comments
Post a Comment