Filter special characters in RadTextbox without using regular expression

10 posts, 0 answers
  1. Abhi
    Abhi avatar
    15 posts
    Member since:
    Sep 2012

    Posted 22 Aug 2012 Link to this post

    Hi all,
    I have 2 problems to solve.
    1. I am trying to filter a rad textbox in client side. I need to restrict special characters in it. Is there any control like FilteredTextBoxExtender to filter rad textbox ?

     I am really fed up with this.Please provide me a solution for this.

    thanks
    Abhi
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Aug 2012 Link to this post

    Hi,

    One suggestion is that you can check for regular expression in OnKeyPress event.
    JS:
    function OnKeyPress(sender, eventArgs)
     {
       var char = eventArgs.get_keyCharacter();
       var exp = /[^a-zA-Z0-9-]/g;
       if (exp.test(char))
       {
        eventArgs.set_cancel(true);
       }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Abhi
    Abhi avatar
    15 posts
    Member since:
    Sep 2012

    Posted 22 Aug 2012 Link to this post

    HI,
    Thanks for your suggestion. But this OnKeyPress event have some browser compatibility issue. Can we use FilteredTextBoxExtender like control to filter rad textbox.

    thanks
    abhi
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 27 Aug 2012 Link to this post

    Hi Abhi,

    The FilteredTextBoxExtender can't be used for RadInputControls it can be applied on asp:TextBoxes.

    Regards,
    Vasil
    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.
  6. Abhi
    Abhi avatar
    15 posts
    Member since:
    Sep 2012

    Posted 07 Sep 2012 Link to this post

    Hi Vasil,
    Then how can i restrict special characters in RadTextBox on key press event . Please provide me solution please.

    Thanks
    Abhi
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Sep 2012 Link to this post

    Hi,

    Try the following javascript to allow only alphabets in RadTextBox.

    JS:
    function OnKeyPress(sender, eventArgs)
        {
            var c = eventArgs.get_keyCode();
            if ((c < 65) || (c > 90 && c < 97) || (c > 122))
                eventArgs.set_cancel(true);
        }
    Also check the following help documentation which explains more about this.
    OnKeyPress.

    Thanks,
    Shinu.
  8. Sharmin
    Sharmin avatar
    8 posts
    Member since:
    May 2012

    Posted 26 Nov 2012 Link to this post

    This function is OK. But if you are copying a text ~!@#$%^&*()_+-={}|[]\:";'<>?,./` to your textbox, this function will not be called.
    I guess Regex expressions are the best way to use it on save.
  9. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 27 Nov 2012 Link to this post

    Hi Sharmin,

    You can override the _onTextBoxPasteHandler handler such way:
    Telerik.Web.UI.RadInputControl.prototype.orgPasteHandler = Telerik.Web.UI.RadInputControl.prototype._onTextBoxPasteHandler ;
     
    Telerik.Web.UI.RadInputControl.prototype._onTextBoxPasteHandler = function(e)
    {
         //do your logic here; then execute the original handler if you need:
        this.Telerik.Web.UI.RadInputControl.prototype.orgPasteHandler(e);
    }


    All the best,
    Vasil
    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.
  10. Jim
    Jim avatar
    1 posts
    Member since:
    Feb 2013

    Posted 03 Jun 2013 Link to this post

    Hi,

    Can someone post an example of how to override the _onTextBoxPasteHandler handler in VB?

    Thanks,
    Jim
  11. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 03 Jun 2013 Link to this post

    Hello Jim,

    The code is JavaScript (not C# or VB). You just need to wrap it with <script> tag and place under the declaration of your ScriptManager in your ASPX page.

    Regards,
    Vasil
    Telerik
    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
UI for ASP.NET Ajax is Ready for VS 2017