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

Issue with radnumeric textbox not allow decimal point and negative character

1 Answer 72 Views
Input
This is a migrated thread and some comments may be shown as answers.
Jiju
Top achievements
Rank 1
Jiju asked on 28 Jun 2013, 12:09 PM
hi,

i am using radnumeric text box in my page and i used following javascript function to avoid both decimal point and negative symbol

function DecimalKeyPress(sender, args) {
                var keyCharacter = args.get_keyCharacter();

                if (keyCharacter == sender.get_numberFormat().DecimalSeparator ||
        keyCharacter == sender.get_numberFormat().NegativeSign) {
                    args.set_cancel(true);
                }

But there seems to be an issue with Firefox as delete key is not working. We found that both delete and decimal key return the same key character as 46. It works with all other browsers.

How can i fix this issue.

Regards
Jiju

1 Answer, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 03 Jul 2013, 11:23 AM
Hello Jiju,

Thank you for contacting Telerik support.

The OnKeyPress client side event is fired only in Firefox when a non-printable character key is pressed. The "." key has a keyCode = 0 and charCode = 46. The "Delete" key has a keyCode= 46 and charCode = 0.

You could use the get_domEvent() function to get the charCode for the pressed key. If it is equal to 0 it means that a non-printable key (del, home, end, etc.) was pressed.

You could modify the Javascript function you have a little to get the result you are looking for. The function would look similar to this:

function DecimalKeyPress(sender, args) {
    var keyCharCode = args.get_domEvent().rawEvent.charCode;
     
    if (keyCharCode == sender.get_numberFormat().DecimalSeparator.charCodeAt() || keyCharCode == sender.get_numberFormat().NegativeSign.charCodeAt()) {
        args.set_cancel(true);
    }
}

Let me know if this modification is working for you.

Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Input
Asked by
Jiju
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or