Regular expressions to allow UTF characters through Jquery

|
| By Webner

Regular expressions provide a powerful way of adding validations to the web forms.

To allow UTF encoded characters (Letters) either UTF -8 or UTF -16 like Á á É é Í ÑÓ ¿ € ₧ å ∫ ç ∂´ƒ ©˙ ∆˚ ¬µ ˜ø π œ ® ß † ¨√ ∑ ≈ ¥ Ω ¡™ £ ¢¡™£¢∞§ ¶

Use Regex expression \p{L}

Here L stands for ‘Letter’ from any language. It includes all the utf encoded characters from all languages.

For example:

var regex =/^([\p{L}])+$/;
regex.test("Веб-решения"); // true
regex.test(“网络解决方案”); // true
regex.test(ویب مسائل کے حلة"); // true

If we want to allow only math symbols, currency signs, box-drawing characters, etc. Then use regex expression \p{S}

For Example:

var regex = x =/^([\p{S}])+$/;
regex.test(“√ ∑ø π£€” ); //true;

Leave a Reply

Your email address will not be published. Required fields are marked *