Zero in front

5 posts, 0 answers
  1. L
    L avatar
    295 posts
    Member since:
    Apr 2008

    Posted 28 Jan 2011 Link to this post

    hi

    I am using numeric textbox but i am having a problem putting a zero in front. eg 012378.

    How should i solve this? thanks
  2. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 28 Jan 2011 Link to this post

    Hello L,

    This is not supported out-of-the-box. In fact you could modify the default positive/negative patterns in order to add a leading zero however you might encounter some unwanted effects.
    <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
        <NumberFormat PositivePattern="0n" />
    </telerik:RadNumericTextBox>

    Regards,
    Daniel
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 15 Apr 2011 Link to this post

    Hello,

    what kind of " unwanted effects"?
    Thinking of using <NumberFormat PositivePattern="000n" />

    (Scenario: user must input one of these: http://www.unnumber.net , stored as varchar(4))

    EDIT:
    Well, combined with MaxLength="4", I see the  unwanted effects: Input can become longer than 4 digits...
  5. Nicolaï
    Nicolaï avatar
    160 posts
    Member since:
    Apr 2008

    Posted 15 Apr 2011 Link to this post

    Javascript solution:

    <telerik:RadNumericTextBox runat="server" ID="un_numberTB" Width="40"
        MaxLength="4" NumberFormat-DecimalDigits="0">
        <NumberFormat AllowRounding="true" GroupSeparator="" />
        <ClientEvents OnValueChanged="addZeros" />
    </telerik:RadNumericTextBox>

    function addZeros(sender,eventArgs)
    {var senderVal=sender.get_textBoxValue();
    if (senderVal.length==0) {sender.set_value("");}
    else if (senderVal.length<4)
        {   var PPattern;
            if (senderVal.length==3) {PPattern="0n";}
            else if (senderVal.length==2) {PPattern="00n";}
            else if (senderVal.length==1) {PPattern="000n";}
            sender.get_numberFormat().PositivePattern=PPattern;
        }
    else {sender.get_numberFormat().PositivePattern="";}
    }

  6. Fabio
    Fabio avatar
    8 posts
    Member since:
    Sep 2013

    Posted 08 Oct 2013 Link to this post

    Here my client solution


    function
    valueChanged(sender,eventArgs)
    {
    fixDisplayTest(sender, 5);
    }
     
    function fixDisplayTest(sender, numChars){
    sender.set_displayValue(padleft(sender.get_value().toString(), '0', numChars));
    }
     
    function padleft(val, ch, num) {
        var re = new RegExp(".{" + num + "}$");
        var pad = "";
        if (!ch) ch = " ";
        do {
            pad += ch;
        } while (pad.length < num);

        
    return re.exec(pad + val)[0];
    }

    Then add valueChanged client Event

    <telerik:RadNumericTextBox ID="MyRadNumeric" runat="server" MaxLength="5" Width="70px">
        <NumberFormat DecimalDigits="0" GroupSeparator="" />
        <ClientEvents OnValueChanged="valueChanged" />
    </telerik:RadNumericTextBox>

    Fabio
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017