Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Need help! I need to add lead zeros to a textbox

Reply
Thread Tools

Need help! I need to add lead zeros to a textbox

 
 
Teep
Guest
Posts: n/a
 
      06-21-2004
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!
 
Reply With Quote
 
 
 
 
Martin Marinov
Guest
Posts: n/a
 
      06-21-2004
Do you want to do it on clien side or server side ?

on server side it is simple :

If txtRefNum.Text.Length < 9 Then
Dim zeros as String = ""
Dim index as Integer = 0
For index = txtRefNum.Text.Length To 8
zeros &= "0"
Next
txtRefNum.Text = zeros & txtRefNum.Text
End If

Regards
Martin

"Teep" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I have a simple text box called txtrefnum, if the user enters a number
> length less than 9 characters long than I need to have lead zeros
> added to it. Does anyone know how to do this? I couldn't find anything
> online on the subject...
>
> <asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>
>
> I thought I could use a validator for the process and make the user
> add the zeros, but of course that is a big no-no! Please help!!
>
> Thanks!



 
Reply With Quote
 
 
 
 
Larry Marburger
Guest
Posts: n/a
 
      06-21-2004
No need to write your own Pad() method, there's a String.PadLeft()
method built into .NET. Check here for examples:

http://msdn.microsoft.com/library/de...dlefttopic.asp

That article demonstrates an easier / cleaner way to accomplish this
task. An example:

<snip>
string temp = txtRefNum.Text.PadLeft(9, '0');
</snip>

This should be what you're looking for, Teep.


Martin Marinov wrote:

> Do you want to do it on clien side or server side ?
>
> on server side it is simple :
>
> If txtRefNum.Text.Length < 9 Then
> Dim zeros as String = ""
> Dim index as Integer = 0
> For index = txtRefNum.Text.Length To 8
> zeros &= "0"
> Next
> txtRefNum.Text = zeros & txtRefNum.Text
> End If
>
> Regards
> Martin
>
> "Teep" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
>
>>I have a simple text box called txtrefnum, if the user enters a number
>>length less than 9 characters long than I need to have lead zeros
>>added to it. Does anyone know how to do this? I couldn't find anything
>>online on the subject...
>>
>><asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>
>>
>>I thought I could use a validator for the process and make the user
>>add the zeros, but of course that is a big no-no! Please help!!
>>
>>Thanks!

>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Lead/ Lead Software Engineer -Immediate Requirement Ann Javascript 1 01-02-2008 04:34 AM
Java Lead/ Lead Software Engineer Ann Java 0 09-06-2007 09:55 AM
Sr.Developer / Team Lead / Proj Lead / Project Manager /Tech Lead for Datamatics Ltd., Mumbai supriyab17@gmail.com Java 0 11-22-2006 05:13 AM
how add zeros to numbers... =?Utf-8?B?QXNoYQ==?= ASP .Net 3 01-19-2005 02:35 PM
Help! Need to add lead zeros to a textbox input TN Bella ASP .Net 6 06-21-2004 08:46 AM



Advertisments