JSFiddle - React, Tailwind, and code Playground

by lionking0

HTML

<div id="container">
    <h2> أدخل نص مع تكرار حرف معين عدة مرات. </h2>
    <label>أدخل النص:</label>
    <input type="text" name="txt" id="txt" onkeydown="charLimit(this, 3);" />
</div>

CSS

body {
    direction: rtl;
}
#container {
    margin-right:60px;
}
#txt {
    border:1px groove #B7B7B7;
}

JavaScript

function charLimit(element, repeat) {
    var pattern = new RegExp('(.)\\1{' + (repeat - 1) + '}');
    element.value = element.value.replace(pattern, "");
}