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

Zero in front

4 Answers 147 Views
Input
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 28 Jan 2011, 02:35 PM
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

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Jan 2011, 03:25 PM
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.
0
Nicolaï
Top achievements
Rank 2
answered on 15 Apr 2011, 07:35 AM
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...
0
Nicolaï
Top achievements
Rank 2
answered on 15 Apr 2011, 10:07 AM
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="";}
}

0
Fabio
Top achievements
Rank 1
answered on 08 Oct 2013, 08:48 AM
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
Tags
Input
Asked by
L
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Nicolaï
Top achievements
Rank 2
Fabio
Top achievements
Rank 1
Share this question
or