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

Restrict input to alphanumeric characters

1 Answer 489 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Cameron Tinker
Top achievements
Rank 1
Cameron Tinker asked on 10 Jun 2010, 07:06 PM

I have a large text input area where users will query information from a database. I want to restrict input to only alphanumeric keys to help prevent SQL injection. I was using a RadTextBox with the multiline attribute set and I had attached the jQuery script alphanumeric to the field, but it disabled the browser context menu. I decided to give the RadEditor a try since it allows for custom context menus and for a toolbar. The jQuery alphanumeric plugin is very nice and if there is any way to attach the script to the content area of the RadEditor, I would appreciate it. If there is another way to achieve the same effect, let me know. Thanks.

This is the basic syntax for applying the alphanumeric filter to a textbox:

<script type="text/javascript">  
    $('.textbox').alphanumeric({ allow: "_-* " });  
</script> 

Then you would have an element such as a RadTextBox or a plain TextBox and apply '.textbox' to the the CssClass attribute.

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 14 Jun 2010, 03:26 PM
Hi Cameron,

The content area of RadEditor is not a textbox but an editable IFRAME element and it seems that the alphanumeric jQuery plugin does not works for IFRAME elements.

I set a class name to the editor's IFRAME and its document content area but the plugin did not work, e.g.

<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad"></telerik:RadEditor>
<script type="text/javascript">
    function OnClientLoad(editor) {

        editor.get_contentAreaElement().className = "editor1";
        editor.get_document().body.className = "editorBody"
    }

$('.editor1').alphanumeric();
$('.editorBody').numeric();

</script>

Since I am not aware how this plugin works, I suggest you to try the isAlphaNumericKey function provided in the following forum thread: Charector limit in Rad:Editor

Regards,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Editor
Asked by
Cameron Tinker
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or