Skip to content
Advertisement

why are arabic numbers (١٢٣) not accepted in textboxes as real numbers?

while developing one of my sites, i noticed that if I enter arabic numbers (١٢٣), they are not interpreted as real number values. Then, I tested a few other sites only to find that they also don’t accept arabic numbers.

The problem is, my client seems to require this functionality (accepting arabic numbers).. and I have no idea where to start. My platform is magento (php).

Advertisement

Answer

To allow PHP to accept the Arabic numbers or Persian numbers (Farsi) (١٢٣٤٥), I developed this easy function:

JavaScript

Note: TO GET THE CORRECT RESULT from text field in your form, you have to use the htmlspecialchars_decode() function. For example:

JavaScript

To keep your code safe, add strip_tags(). For example:

JavaScript

Please don’t hesitate to ask me if you have any further question about this function.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement