Filtering input text with jQuery

I want to filter and block text input. For example, in some cases, the user can only enter Persian / Farsi characters but not English, or when the user can enter English but not Persian. So some input only accepts Persian / Farsi characters, while others only accept English.

Also I found this http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input . If you know any regular checkout for Persian characters can help me or how to change keyboard mode.

thank.

+3


source to share


1 answer


According to the Unicode character list , you need to check for characters in the Unicode range U+0600-U+06FF

.

So, if you want to prevent any other unicode character from being inserted, you can simply check your input value against a /^[\u0600-\u06FF]+$/g

regex. Also note that there are many Unicode ranges you can allow. On the Arabic Unicode Encoding page , next to Arabic (0600-06FF, 225 characters) you have

  • Arabic application (0750-077F, 48 characters)
  • Arabic Extended-A (08A0-08FF, 39 characters)
  • Arabic Presentation Form-A (FB50-FDFF, 608 characters)
  • Arabic Presentation Form-B (FE70-FEFF, 140 characters)
  • Rumi Numeral Symbols (10E60-10E7F, 31 characters)
  • Arabic mathematical alphabetic characters (1EE00-1EEFF, 143 characters)

in this case add as many times as you need in the expression:
for example/^[\u0600-\u06FF\u0750-\077F\u0...]+$/g



So, using the mentioned snippet you should write

$('#text_input').filter_input({regex:'[\u0600-\u06FF\u0750-\077F\u0...]'}); 

      

Hope this helps. السلام عليكم

+4


source







All Articles