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

T

Teep

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!
 
M

Martin Marinov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top