I would like to let users type both Arabic ( ٠١٢٣٤٥٦٧٨٩ ) and English ( 0123456789 ) numbers when they toggle the keyboard language, how can I achieve this ?
Asked
Active
Viewed 2,295 times
4
-
1As 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 Answers
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
-
It doesn't help, because the input field itself converts the Arabic numbers into English ones. So they are all displayed in English. – Mina Soleimanzadeh Aug 16 '21 at 04:23