www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > HTML

    HTML Discussion and technical support for building, using and deploying HTML sites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-21-2009, 09:29 PM
    semiNoob0820 semiNoob0820 is offline
    Registered User
     
    Join Date: Feb 2009
    Location: Chicago
    Posts: 24
    limiting number of characters...

    I read at multiple places on the web that there IS NO WAY to limit the number of characters a user enters in a "<input type="text">" and <textarea> with just HTML. I was looking for confirmation on this since I don't believe 100 percent everything I read on the web. Is this true?

    Can anyone confirm that the best way to limit the amount of characters a user enters in input forms is to use BOTH Javascript(clientSide) checks AND PHP(serverSide) checks. Thanks guys!
    Reply With Quote
      #2  
    Old 11-22-2009, 01:48 AM
    Shorts Shorts is offline
    Web Developer
     
    Join Date: Sep 2008
    Posts: 329
    For textareas yes, there is no way. Input[type='text'] has an attribute of maxlength.

    Best way is via PHP backend and frontend with JavaScript, as you said. PHP being the best part, since JavaScript can be spoofed.
    __________________
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...
    Reply With Quote
      #3  
    Old 11-22-2009, 05:13 AM
    opifex's Avatar
    opifex opifex is offline
    ignorance is curable...
     
    Join Date: Sep 2008
    Location: Mexico
    Posts: 784
    HTML Code:
    <input type="text" id="field_1" name="field_1" maxlength="5" />
    will only permit 5 characters,
    <textarea> can only be limited by script as Shorts said. You can do client side form validation with javascript, but ALWAYS back that up with server side validation in your form processor whether it be PHP, Perl or ASP or whatever.

    The web is FULL of errors... but if everything was correct it wouldn't be as interesting as it is.
    __________________
    ...but stupidity is terminal.
    Reply With Quote
      #4  
    Old 11-22-2009, 11:27 AM
    semiNoob0820 semiNoob0820 is offline
    Registered User
     
    Join Date: Feb 2009
    Location: Chicago
    Posts: 24
    great stuff guys... thanks so much for the info on maxlength ...
    Reply With Quote
      #5  
    Old 11-23-2009, 06:43 AM
    semiNoob0820 semiNoob0820 is offline
    Registered User
     
    Join Date: Feb 2009
    Location: Chicago
    Posts: 24
    I have two more QUICK questions if you guys could answer:

    1) so for a quick check on <input type="text">, the "maxlength" attribute is enough by ITSELF (remember that I will ALSO be doing a server-side check as well so I didn't feel the need to do Javascript check for <input type="text">)

    2) for my Javascript check on <textarea> I used this resource:
    http://www.mediacollege.com/internet...haracters.html
    Please check that resource out, and let me know if that Javascript textarea check is good enough?

    Thanks again in advance. Also, I believe if these two questions can be answered then this thread will prove to be incredibly useful to many people since it answers such a common question and gives resources all in ONE PLACE.

    Thanks again guys...
    Reply With Quote
      #6  
    Old 11-23-2009, 06:52 AM
    semiNoob0820 semiNoob0820 is offline
    Registered User
     
    Join Date: Feb 2009
    Location: Chicago
    Posts: 24
    Oh, and one more thing. I noticed that when I do implement the <textarea> check used at that resource ( http://www.mediacollege.com/internet...haracters.html ), when I click on the <textarea> to insert text it strangely adds about 9 extra blank spaces to the <textarea> in front of the message before user types in anything.

    This is very strange indeed as I disected the HTML markup and Javascript for any ways or reasons why it adds this extra space, but still can't find an answer.

    Note: Before I implemented the Javascript <textarea> character # check, this extra blank space in the <textarea> NEVER occurred.
    Reply With Quote
      #7  
    Old 11-23-2009, 08:00 AM
    opifex's Avatar
    opifex opifex is offline
    ignorance is curable...
     
    Join Date: Sep 2008
    Location: Mexico
    Posts: 784
    As is, it's a nice check... simple.

    Couldn't replicate the "inserting spaces" problem in Firefox,Chromium or Opera.
    The referenced page does have some errors ... specific to <textarea>, but won't cause that problem. Validate the page and they stick out.
    __________________
    ...but stupidity is terminal.
    Reply With Quote
      #8  
    Old 11-23-2009, 08:12 AM
    semiNoob0820 semiNoob0820 is offline
    Registered User
     
    Join Date: Feb 2009
    Location: Chicago
    Posts: 24
    oh ok so are you saying that the extra space problem is isolated to my situation? can someone else confirm this please? I have NO IDEA why I am getting these extra spaces... also...

    can someone give some feedback on:
    1) so for a quick check on <input type="text">, the "maxlength" attribute is enough by ITSELF (remember that I will ALSO be doing a server-side check as well so I didn't feel the need to do Javascript check for <input type="text">)
    Reply With Quote
      #9  
    Old 11-23-2009, 08:28 AM
    opifex's Avatar
    opifex opifex is offline
    ignorance is curable...
     
    Join Date: Sep 2008
    Location: Mexico
    Posts: 784
    <input type="text".... maxlength="13"/> is a given... you just cannot put more into the fiels than 13 characters in this case. No client side check needed for number of characters... maybe needs validation for content though, depending on what you are doing.
    __________________
    ...but stupidity is terminal.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:29 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.