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

RadNumericTextBox and scientific notation

1 Answer 62 Views
Input
This is a migrated thread and some comments may be shown as answers.
R
Top achievements
Rank 1
R asked on 17 Jun 2013, 06:00 PM
Hello,
how to allow a user to enter a number type 1.2e-36 in a radnumnertextebox ?
Thanx

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 20 Jun 2013, 03:41 PM
Hello,

Generally, this requirement is not supported since the RadNumericTextBox is for numbers only and does not allows letters. You can use RadTextBox or RadMaskedTextBox to achieve the requested functionality.

Nevertheless, you can try this approach to work around the default behavior:
<telerik:RadNumericTextBox ID="RadNumericTextBox1" Skin="Default" runat="server">
    <ClientEvents OnKeyPress="keyPress" OnValueChanged="valueChanged" />
</telerik:RadNumericTextBox>
JavaScript:
<script type="text/javascript">
    //Put your JavaScript code here.
    Telerik.Web.UI.RadNumericTextBox.prototype._compileRegEx = function () {
        var regexDecimalSeparator = this.get_numberFormat().DecimalSeparator == "." ? "\\." : this.get_numberFormat().DecimalSeparator;
        this._acceptRegExp = new RegExp("[e0-9" + regexDecimalSeparator + this.get_numberFormat().NegativeSign + "]{1}");
        this._rejectRegExp = new RegExp("[^e0-9" + regexDecimalSeparator + this.get_numberFormat().NegativeSign + "]{1}", "g");
        this._decimalReplaceRegExp = new RegExp(regexDecimalSeparator, "g");
    };
    var orgNegativeSign = "";
    function keyPress(sender, args) {
        if (args.get_keyCode() == 45) {
            orgNegativeSign = sender.get_numberFormat().NegativeSign;
            sender.get_numberFormat().NegativeSign = "~";
        }
    }
    function valueChanged(sender, args) {
        if (orgNegativeSign != "") {
            sender.get_numberFormat().NegativeSign = orgNegativeSign;
            orgNegativeSign = "";
        }
    }
</script>

Hope this helps. Please give it a try and let  me know if it works for you.

Regards,
Eyup
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
R
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or