I want a javascript function that will prevent the same character from appearing more than 3 times in a row in an input field. I know how to do this easily with 1 repeat. For example...
function deleteit() {message.value=message.value.replace(/(.)\1/g,'')}
<input type='text' id='message' onkeyup='deleteit()'>
If you enter the same character more than once here, the second gets deleted. I want to allow up to 3 and delete on the 4th. For example, "Yippy!!!" would be acceptable but typing "Yippy!!!!" would delete the 4th exclamation point. I tried changing the regex to /(..)\1/g That does work, but not quite. It's deleting 2 "Groups" of characters, so if I typed something like "YOYO" it would delete that. How can I change 4 or more of the same character to 3.