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

  • Thread starter Thread starter Teep
  • Start date Start date
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!
 
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
 
Back
Top