I have a radtextbox.
how this radtextbox can be restricted to only numbers.
means only numbers should be entered in textbox.
thanks to all.
1 Answer, 1 is accepted
You can use RadNumericTextBox which restricts user input to numeric values. Take a look at the following help article for more on this.
RadNumericTextBox Basics.
In the case of RadTextBox, you can achieve this by using Regular expression. Here is a sample code to achieve the same.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server"> <ClientEvents OnKeyPress="keyPress" /> </telerik:RadTextBox >function keyPress(sender, args) { var text = sender.get_value() + args.get_keyCharacter(); if (!text.match('^[0-9]+$')) args.set_cancel(true); }Thanks,
Shinu.
thanks
stil character cab be copy and paste, how it can be restricted.
Try this approach.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"> <ClientEvents OnKeyPress="keyPress" /></telerik:RadTextBox>Thanks,
Shinu.
With reference to this forum thread there is no native way to prevent users from entering more than X decimal numbers. However, you can subscribe to the KeyPress client event and cancel it if a specific number of decimal places has been reached. Note that you will have to check what is the current caret position as follows.
ASPX:
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server"> <NumberFormat DecimalDigits="2" AllowRounding="true" /> <ClientEvents OnKeyPress="preventMoreDecimalPlaces" /></telerik:RadNumericTextBox>JS:
<script type="text/javascript">function preventMoreDecimalPlaces(sender, args){ var separatorPos = sender._textBoxElement.value.indexOf(sender.get_numberFormat().DecimalSeparator); if (args.get_keyCharacter().match(/[0-9]/) && separatorPos != -1 && sender.get_caretPosition() > separatorPos + sender.get_numberFormat().DecimalDigits) { args.set_cancel(true); }}</script>Hope this helps.
Regards,
Princy.
Hi,
in my application radmaskedtextbox should allow 9999999999(##########) number, here # is represent should 9(nine) number how to write RegularExpressionValidator validation
my application account number is is 9999999999 so user enter only 9999999999
ex:- 1)user enter 9999999998 show error enter only 9999999999
2) user enter 9999999999 radmaskedtextbox accepting now there is no validataion,
3) user enter 10000000000 show error enter only 9999999999
4) user enter 9874561239 show error enter only 9999999999
is it possible or not please help me
I am not sure what could be the use case of such requirement, since the user will be allowed to enter only one value. Nevertheless, you could try to use CustomValidator in the following manner:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> function validateValue(sender, args) { var textBox = $find("<%=RadMaskedTextBox1.ClientID%>"); if (textBox.get_value() != "999999") { args.IsValid = false; } } </script></telerik:RadCodeBlock><telerik:RadMaskedTextBox runat="server" Mask="######" ID="RadMaskedTextBox1"></telerik:RadMaskedTextBox><asp:CustomValidator runat="server" ID="CustomValidator1" ErrorMessage="Value must be 999999" Display="Dynamic" ClientValidationFunction="validateValue"></asp:CustomValidator><telerik:RadButton runat="server" Text="Test"></telerik:RadButton>Hope this helps.
Regards,
Konstantin Dikov
Telerik
See What's Next in App Development. Register for TelerikNEXT.
hello dude its great to receive your sharing of knowledge
i have a Rad text box at winforms where i need to filter only numbers and email validation in another text box how can i apply that code or reference to filter it
I am using the below radtextbox and the onkeyup is not working for it. Below is the code:
<td align="left" style="Width:80px; padding-bottom:10px;"><telerik:RadTextBox ID="SphereRightText" runat="server" width="50" OnKeyUp="doRightSphereValidation();" onchange="FormatRightSphere(2, true);" /></td>
function doRightSphereValidation()
{
if (IsRightLensItemSelected())
{
var textBox = $find("<%=SphereRightText.ClientID %>");
return validation_ValidateNumericTextBox(textBox, RightSphereMinimum, RightSphereMaximum, false, TurnInvalidInputsRed());
}
else
{
return true;
}
}
The code snippet fires the doRightSphereValidation function as expected on my side, but this is a handler added to the element of the RadTextBox and it is not an event from the API. If you need to use the control events you should handle the ClientEvents-OnKeyPress="functionName".
Hope this helps.
Regards,
Konstantin Dikov
Telerik by Progress
Hi Shunu,
I am facing a problem to restrict the special character by using javascript, I have implemented the same thing as you mentioned and called the function on keypress event of RadTextBox but One of our end user has disabled/stopped the javascript from client browser and he/she has insert the special character,
kindly suggest me something what I have to do.
Thanks,
Majeed Khan
I've already replied to this query in the following post:
https://www.telerik.com/forums/don-t-allow-user-to-write-special-characters-in-radtextbox
I suggest that we continue our discussion on the mentioned thread.
Regards,
Eyup
Progress Telerik
Hi Princy,
This is very urgent , can i do this for radsearchbox input text also,
need reply really soon
i have put a search box in which currency code is populated in the dropdown of searchbox and want to restrict user to put only number (as the amount) please help
Hi there,
You can see how to attach to the key press event of the search textbox via jQuery in this forum thread: https://www.telerik.com/forums/how-to-attach-client-event-to-textbox-inside-radsearchbox#yv46_mWfuUqx4dV0uzg7aA.
<script type="text/javascript">
function pageLoad() {
var $ = $telerik.$;
$(".rsbInput ").keypress(function (event) {
if (event.which == 13) {
alert("enter pressed");
}
});
}
</script>Regards,
Rumen
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.