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

Filter special characters in RadTextbox without using regular expression

9 Answers 630 Views
Input
This is a migrated thread and some comments may be shown as answers.
Abhi
Top achievements
Rank 1
Abhi asked on 22 Aug 2012, 10:35 AM
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

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Aug 2012, 11:24 AM
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.
0
Abhi
Top achievements
Rank 1
answered on 22 Aug 2012, 12:52 PM
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
0
Vasil
Telerik team
answered on 27 Aug 2012, 12:54 PM
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.
0
Abhi
Top achievements
Rank 1
answered on 07 Sep 2012, 05:32 AM
Hi Vasil,
Then how can i restrict special characters in RadTextBox on key press event . Please provide me solution please.

Thanks
Abhi
0
Shinu
Top achievements
Rank 2
answered on 07 Sep 2012, 09:24 AM
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.
0
Sharmin
Top achievements
Rank 1
answered on 26 Nov 2012, 05:16 PM
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.
0
Vasil
Telerik team
answered on 27 Nov 2012, 11:47 AM
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.
0
Jim
Top achievements
Rank 1
answered on 03 Jun 2013, 10:48 AM
Hi,

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

Thanks,
Jim
0
Vasil
Telerik team
answered on 03 Jun 2013, 02:14 PM
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.
Tags
Input
Asked by
Abhi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Abhi
Top achievements
Rank 1
Vasil
Telerik team
Sharmin
Top achievements
Rank 1
Jim
Top achievements
Rank 1
Share this question
or