Restrict the input to specific language

4 posts, 0 answers
  1. Ibrahim
    Ibrahim avatar
    2 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2012 Link to this post

    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..
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 19 Jul 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ibrahim
    Ibrahim avatar
    2 posts
    Member since:
    Jul 2012

    Posted 22 Jul 2012 Link to this post

    Hi Eyup,
    Thank you for your reply..its work perfectly..
    also, what I can do to Restrict to English only..


    Thanks
  5. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 24 Jul 2012 Link to this post

    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.
Back to Top