RadNumericTextBox and scientific notation

2 posts, 0 answers
  1. R
    R avatar
    1 posts
    Member since:
    Jun 2013

    Posted 17 Jun 2013 Link to this post

    Hello,
    how to allow a user to enter a number type 1.2e-36 in a radnumnertextebox ?
    Thanx
  2. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 20 Jun 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top