4

I would like to let users type both Arabic ( ٠١٢٣٤٥٦٧٨٩ ) and English ( 0123456789 ) numbers when they toggle the keyboard language, how can I achieve this ?

Hesham AbdAllah
  • 412
  • 6
  • 16
  • 1
    As far as I tested. In programming non-English numerals are not treated as numbers so you can't really do with number input. Change type of input to `text`. – ShivCK May 06 '19 at 20:11
  • You can use regex and add a `0-9` to the character set from here: [Regular Expression for arabic numbers](https://stackoverflow.com/questions/4134058) `/^[0-9\u0660-\u0669]+$/` – adiga May 06 '19 at 20:21

1 Answers1

0

As far as I am aware, there is no way to change the built-in behavior of <input type="number"> in order to achieve what you want.

One possible workaround is to use a text input, with a specified pattern that satisfies both English and Arabic numbers, e.g.:

<form>
    <input type="text" pattern="^([0-9]+([\.][0-9]+)?)|([\u0660-\u0669]+([\.][\u0660-\u0669]+)?)$">
    <input type="submit" value="Submit">
</form>

This is a possible regex, probably not the best, that matches against decimal numbers in either Arabic or English. If you only need integers, a much simpler regex could work, as per @adiga's comment.

Anis R.
  • 6,656
  • 2
  • 15
  • 37