How to TRIM zeroes from the left portion of a string

Classic ASP VBScript


I have a login page for our team where a user enters their employee number.  Sometimes, however, they enter their "full" employee number, which just contains 3 leading zeroes ("000.....") before their number.

This, of course, causes problems when logging in because the entered datat does not contain the leading zeroes.

I would like for any zeroes to the left of a number to be ignored, or removed, from the login after the user presses "submit".  I was looking at TRIM, LTRIM, RTRIM, but they appear to just remove spaces.

How could I accomplish removing/ignoring zeroes?

Example emp number:  203456
Example login (Sometimes): 000203456

Basically, I would like any number of zeroes (Whether 2 or 5, etc.) to be removed/ignored from the left side until it reaches any number other than zero.

Thanks so much,
Who is Participating?
hieloConnect With a Mentor Commented:
That's effectively what CInt() will do. Did you try it? If you are having problems then add zero the result of CInt():

Dim x
x = 0 + CInt(x)

x should now be just 123
Dim x
x = CInt(x)
lshaneAuthor Commented:
Thanks, hielo, for your reply.  That's kind of what I need.  More specifically, though, I need to remove any number of zeroes in the front before a "different" number appears.

Sometimes a user could enter "00123456"...
Other times they could enter "000123456"...
Or even "0123456"...

I just want to be able to have it ignore/remove any zero (however many) in the beginning of the string UNTIL it hits the first "different" number (1, 2, 3, 4, etc.).

Is that possible?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

lshaneAuthor Commented:
Hello, hielo.

OK - yes, it did work - to a certain degree.

However... if I type "000123456" or even "123456" then I get the following error:
Error Type:
Microsoft VBScript runtime (0x800A0006)
Overflow: 'CInt'
/testpmcct2/testloginresults.asp, line 5

Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 2.0.50727)

POST 42 bytes to /testpmcct2/testloginresults.asp

POST Data:

It's almost like it gives the error if I type MORE than 5 numbers other than zero.
True:  It does remove any zeroes from the beginning, however, it only accepts a 5-digit number after that.

How can that be extended?
lshaneAuthor Commented:
Hi, hielo.

I discovered if I remove the "C" from the "Cint", that it is able to extend the numbers.

So, what is the significance of the "C" in "Cint" ?

CInt: Converts an expression to a variant of subtype Integer
Int:        Returns the integer part of a specified number

CLng would have also given you a bigger range
lshaneAuthor Commented:
Awesome!  Thanks so much, hielo!  I appreciate it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.