9 Answers, 1 is accepted
0
Mohammed
Top achievements
Rank 2
answered on 14 Aug 2012, 10:57 PM
Hi my friends,
i found a solution for my case and would like to share it with you :
i found a solution for my case and would like to share it with you :
<telerik:RadTextBox ID="rtxtSerialNo" runat="server" MaxLength="40" Width="198px" SelectionOnFocus="SelectAll" > <ClientEvents OnKeyPress="OnKeyPressSerialText"/> </telerik:RadTextBox>function OnKeyPressSerialText(sender, eventArgs) { var char = eventArgs.get_keyCharacter(); //will allow just letters, numbers and "-" letter
var exp = /[^a-zA-Z0-9-]/g; if (exp.test(char)) { eventArgs.set_cancel(true); } }
0
Mayur
Top achievements
Rank 1
answered on 03 Sep 2012, 09:08 AM
Hi Mohammed,
I used your solution it works. But in firefox browser when i try to edit the text using back button or delete button, the editing does not happen. Instead i have to select and over write.
any suggestions ?
I used your solution it works. But in firefox browser when i try to edit the text using back button or delete button, the editing does not happen. Instead i have to select and over write.
any suggestions ?
0
Princy
Top achievements
Rank 2
answered on 03 Sep 2012, 10:44 AM
Hi Manoj,
Modify the code as follows to achieve your scenario.
Javascript:
Hope this helps.
Thanks,
Princy.
Modify the code as follows to achieve your scenario.
Javascript:
<script type=
"text/javascript"
>
function
OnKeyPressSerialText(sender, eventArgs)
{
var
code = eventArgs.get_keyCode();
if
(code == 8 || code == 46 || (36 < code <41))
// Checking whether the key pressed is backspace, Delete or One of the Arrow Keys.
{
return
;
}
var
char = eventArgs.get_keyCharacter();
//will allow just letters, numbers and "-" letter
var
exp = /[^a-zA-Z0-9-]/g;
if
(exp.test(char))
{
eventArgs.set_cancel(
true
);
}
}
</script>
Hope this helps.
Thanks,
Princy.
0
Wayne
Top achievements
Rank 1
answered on 17 Apr 2018, 02:50 AM
Sorry I could not get this to work. Not calling the JS script. Is this also out of date as you don't have OnKeyPress its now ClientEvents-OnKeyPress.
Can you show this sample again with one aspx file and one js file.
Thank you
0
Hello Wayne,
Please try changing the if condition as follows:
I am also sending a sample working web site as requested.
Regards,
Eyup
Progress Telerik
Please try changing the if condition as follows:
if
(code == 8 || code == 46 || (36 < code && code < 41))
I am also sending a sample working web site as requested.
Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0
Majeed
Top achievements
Rank 1
answered on 28 Jul 2018, 09:54 AM
Hi Mohammed,
this is not secured validation because If we disable the javascript from client browser than it will allow to enter restricted characetr in textbox
0
Majeed
Top achievements
Rank 1
answered on 28 Jul 2018, 09:57 AM
Hello Eyup,
I am facing some problem like Using Javascript for validation to restrict some special characters but one of our end user entered special characters by stopping/disabled the javascript from client browser.
kindly suggest me any better solution.
Thanks,
Majeed Khan
0
Hi Majeed,
Generally, for numeric input we suggest that RadNumericTextBox is used:
https://demos.telerik.com/aspnet-ajax/numerictextbox/overview/defaultcs.aspx
As for restricting some special symbols with RadTextBox, you can use javascript as with regular asp:TextBox. If this is not applicable for a specific user, I'm afraid this is not specifically related to Telerik and you can check discussions over the net for regular asp:TextBoxes or inputs on this matter and once you manage to achieve that, then you can use a similar logic for the RadTextBox as well.
Regards,
Eyup
Progress Telerik
Generally, for numeric input we suggest that RadNumericTextBox is used:
https://demos.telerik.com/aspnet-ajax/numerictextbox/overview/defaultcs.aspx
As for restricting some special symbols with RadTextBox, you can use javascript as with regular asp:TextBox. If this is not applicable for a specific user, I'm afraid this is not specifically related to Telerik and you can check discussions over the net for regular asp:TextBoxes or inputs on this matter and once you manage to achieve that, then you can use a similar logic for the RadTextBox as well.
Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.