Methods that no longer allow right-to-left text input
P粉021854777
P粉021854777 2023-08-15 20:00:01
0
1
462
<p>How to prevent or at least detect right to left text input (like Arabic or Hebrew) in an input box? </p>
P粉021854777
P粉021854777

reply all(1)
P粉541796322

You can try to use the dir attribute of the input tag to specify the text direction.

<input type="text" dir="ltr" placeholder="在此输入...">

If this doesn't solve your problem, you can use the javascript interactive check snippet below to do it.

<input type="text" id="textInput" placeholder="在此输入...">
<div id="result"></div>

<script>
const inputElement = document.getElementById('textInput');
const resultElement = document.getElementById('result');

inputElement.addEventListener('input', function() {
  const text = inputElement.value;
  const rtlRegex = /[\u0600-\u06FF\u0750-\u077F\u0590-\u05FF]/;

  if (rtlRegex.test(text)) {
    resultElement.textContent = '检测到从右到左的文本。';
  } else {
    resultElement.textContent = '未检测到从右到左的文本。';
  }
});
</script>

Also check if there are any other CSS rules affecting your input tag.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!