Advanced Search

Results 1 to 5 of 5

Thread: I want to put leading zero automatically

  1. #1
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I want to put leading zero automatically

    I have one field in form and i want to put leading zero automatically like if someone put 1 it should write 0001 and if someone write 11 then 0011 but it should be leading zero automatic.

    I appreciate quick reply

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    While Len(Field) < 4
      Field = "0" & Field
    End While
    I don't know if this is valid ASP (I don't know ASP and am judging from my long-ago knowledge of REALBasic), but that's the general idea of it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Its not i want to put only one zero. it can be one or two or three also.it depend on how many digits someone enters.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Exactly. The above loop will pad Field to four digits with zeroes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hi amit1234! I'm also new to ASP...and similarly got the same problem..

    I found this code and this was a great help in solving that problem...

    http://www.4guysfromrolla.com/demos/FormatDemo.asp

    You need to do some itsy bitsy tweaking on it though if you want it to be automatic... =)

    Hope it helps!

    seraphicmortal

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •