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

Enter only numbers

1 Answer 76 Views
Input
This is a migrated thread and some comments may be shown as answers.
Tina
Top achievements
Rank 1
Tina asked on 24 Oct 2011, 02:29 AM
How can I make RadTextBox enter only numbers?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Oct 2011, 04:36 AM
Hello Tina,

You can achieve this by attaching the client event OnKeyPress. Here is the sample code.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server" >
    <ClientEvents OnKeyPress="keyPress"/>
</telerik:RadTextBox >

Javascript:
<script type="text/javascript">
  function keyPress(sender, args)
  {
    var text = sender.get_value() + args.get_keyCharacter();
    if (!text.match('^[0-9]+$'))
    args.set_cancel(true);
  }
<script>

Thanks,
Shinu.
Tags
Input
Asked by
Tina
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or