How to limit an INPUT field to a number of characters?

Discussion in 'HTML & Website Design' started by campolar, Jul 13, 2008.

  1. #1
    Title says it all, how to limit an INPUT field to a number of characters?
     
    campolar, Jul 13, 2008 IP
  2. amazingronit

    amazingronit Well-Known Member

    Messages:
    1,334
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    130
    #2
    it is fairly simple. just use maxlength="##", replace ## with the required number. or if you want it to appear more attractive, i suggest you to do THIS or THIS to get this thing done!

    hope it helps.
     
    amazingronit, Jul 13, 2008 IP
  3. campolar

    campolar Peon

    Messages:
    2,683
    Likes Received:
    244
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks but after seeing that i figured out that there wasn't actually any need for javascript. Just the tag maxlength="10" helped. Javascript makes it look not good. If u type fast, u see that all u type can be there but as soon as u stop then it disappears but by using the simple maxlength even typing fast wont make any extra text appear.
     
    campolar, Jul 13, 2008 IP
  4. faithnomoread

    faithnomoread Peon

    Messages:
    174
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    maxlength="#ofcharacters"
     
    faithnomoread, Jul 13, 2008 IP
  5. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If it is for something important then you will need to use a server side language to cut the string to 10 characters. The HTML can be changed by the end user, no good for "sensitive" info.
     
    nicangeli, Jul 13, 2008 IP
  6. campolar

    campolar Peon

    Messages:
    2,683
    Likes Received:
    244
    Best Answers:
    0
    Trophy Points:
    0
    #6
    nah its not for "sensitive" info :p its just to make sure people do not make too long username :)
     
    campolar, Jul 14, 2008 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    I would still suggest adding a server side check of the length to make sure nobody tries to game the system.
     
    deathshadow, Jul 14, 2008 IP
  8. campolar

    campolar Peon

    Messages:
    2,683
    Likes Received:
    244
    Best Answers:
    0
    Trophy Points:
    0
    #8
    nah its cool :D
     
    campolar, Jul 14, 2008 IP
  9. chapicha

    chapicha Peon

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thank , I get more toys for my web.
     
    chapicha, Jul 15, 2008 IP