3 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 17 Dec 2012, 12:38 PM
Hi Shajan,
Try the following code snippet.
ASPX:
JS:
Regards,
Shinu.
Try the following code snippet.
ASPX:
<
telerik:RadTextBox
ID
=
"RadTextBox1"
runat
=
"server"
ClientEvents-OnKeyPress
=
"OnKeyPress"
>
</
telerik:RadTextBox
>
JS:
<script type=
"text/javascript"
>
function
OnKeyPress(sender, eventArgs) {
var
char = eventArgs.get_keyCharacter();
if
(char ==
'$'
|| char ==
'#'
|| char ==
'^'
|| char ==
'['
|| char ==
']'
) {
eventArgs.set_cancel(
true
);
}
}
</script>
Regards,
Shinu.
0

Shajan
Top achievements
Rank 1
answered on 17 Dec 2012, 01:35 PM
Dear Shinu,
I implemented this code, with some more special characters(&;`'\|*?~<>^()[]{}$"). But in Fire Fox "The Right Arrow Key" not working.
Please provide me a solution for this.
Thanks and Regards
Shajan
I implemented this code, with some more special characters(&;`'\|*?~<>^()[]{}$"). But in Fire Fox "The Right Arrow Key" not working.
Please provide me a solution for this.
Thanks and Regards
Shajan
0

Shinu
Top achievements
Rank 2
answered on 18 Dec 2012, 05:39 AM
Hi Shajan,
The behavior that you found is because the keycode of ' conflict with right arrow key. With respect to this forum thread you can use the get_domEvent() to get the original DOM event.
JS:
Regards,
Shinu.
The behavior that you found is because the keycode of ' conflict with right arrow key. With respect to this forum thread you can use the get_domEvent() to get the original DOM event.
JS:
<script type=
"text/javascript"
>
function
OnKeyPress(sender, args)
{
var
domEvent = args.get_domEvent();
alert(
"control is held: "
+ domEvent.ctrlKey);
alert(
"alt is held: "
+ domEvent.altKey);
}
</script>
Regards,
Shinu.
SMc
commented on 16 Feb 2023, 10:51 PM
Top achievements
Rank 2
Iron
Veteran
Iron
I wanted to say thank you for the js code. I got it to work! I only wanted to restrict "<" and ">" as the users were getting "Dangerous Code Injection" errors!
function OnKeyPress(sender, eventArgs) {
var char = eventArgs.get_keyCharacter();
if (char == '<' || char == '>') {
eventArgs.set_cancel(true);
}
}
Was all I needed.
Thanks again!
Rumen
commented on 17 Feb 2023, 08:17 AM
Telerik team
Thank you for sharing your solution for the < and > symbols, Sean!
Fore reference I am also adding these two resources on the topic here: