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

Not allow decimal

1 Answer 70 Views
Input
This is a migrated thread and some comments may be shown as answers.
Eva
Top achievements
Rank 1
Eva asked on 20 Dec 2008, 01:49 AM
Is it possible to enter only number.if the user enter  dot (.) it shouldn't display

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 20 Dec 2008, 01:16 PM
Hello Eva,

Here is how to do it:

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" > 
    <ClientEvents OnKeyPress="RadNumericTextBox_KeyPress" /> 
</telerik:RadNumericTextBox> 
 
<script type="text/javascript"
 
function RadNumericTextBox_KeyPress(sender, args) 
    if (args.get_keyCharacter() == ".") 
    { 
        args.set_cancel(true); 
        var eventArgs = new Telerik.Web.UI.InputErrorEventArgs( 
            Telerik.Web.UI.InputErrorReason.ParseError, 
            sender.get_textBoxValue(), 
            args.get_keyCode(), 
            args.get_keyCharacter() 
        ); 
        sender.raise_error(eventArgs); 
    } 
 
</script> 


The Javascript code, which comes after "args.set_cancel(true);" makes the numeric textbox flash for a moment, indicating that you are trying to enter an invalid character.


All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Input
Asked by
Eva
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or