This is a migrated thread and some comments may be shown as answers.

Restrict the input to specific language

3 Answers 1375 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ibrahim
Top achievements
Rank 1
Ibrahim asked on 17 Jul 2012, 07:49 AM
Hi there..

Normally we have English letter keyboards with other languages support. And we can switch between languages by pressing Alt-Shift or Ctrl-Shift, or by selecting the input language from the language bar, and then we can start typing in the selected language.

Currently I am developing a web page where the user should fill some fields in two languages (i.e., filling name in English letters and then filling name in Arabic letters). Normally in this case, the user should fill the name in English and then switch the keyboard language from the keyboard or the language bar.


I want to restrict the input the Arabic text box to accept only Arabic , put also you can pest arabic word,,
I am using ASP.NET AJAX Q1 2012 ..

is there any way in Rad Control to do that?

Thanks..

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 19 Jul 2012, 10:29 AM
Hi Ibrahim,

I am afraid there is no such functionality provided out of the box. However, please try the following approach to achieve the described behavior:
  mark-up:
<telerik:RadTextBox ID="RadTextBox1" runat="server" ClientEvents-OnKeyPress="keyPressed"
        onpaste="onTextPaste()"></telerik:RadTextBox>
  JavaScript:
function keyPressed(sender, args) {
      if (args.get_keyCode() > 64 && args.get_keyCode() < 123) {
          args.set_cancel(true);
          alert("Only Arabic letters allowed");
      }
  }
  var currentText;
  function onTextPaste() {
      currentText = $find("<%= RadTextBox1.ClientID %>").get_textBoxValue();
      setTimeout(checkText, 1);
  }
  function checkText() {
      var totalText = $find("<%= RadTextBox1.ClientID %>").get_textBoxValue();
      for (var i = 0; i < totalText.length; i++) {
          if (totalText.charCodeAt(i) > 64 && totalText.charCodeAt(i) < 123) {
              $find("<%= RadTextBox1.ClientID %>").set_textBoxValue(currentText);
              alert("Text contains Non-Arabic letters");
              break;
          }
      }
  }

That should do the trick. If you want to enable arabic instead of latin numbers you could try:
if (args.get_keyCode() < 1536 || args.get_keyCode() > 1791)


Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ibrahim
Top achievements
Rank 1
answered on 22 Jul 2012, 08:14 AM
Hi Eyup,
Thank you for your reply..its work perfectly..
also, what I can do to Restrict to English only..


Thanks
0
Eyup
Telerik team
answered on 24 Jul 2012, 08:47 AM
Hi Ibrahim,

You could use the same logic for any language you want to restrict per your own requirements. You could find the letters' keyCodes for different languages on various sources on the internet.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Input
Asked by
Ibrahim
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ibrahim
Top achievements
Rank 1
Share this question
or