|
|||||||
| HTML Discussion and technical support for building, using and deploying HTML sites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!
|
|
#2
|
|||
|
|||
|
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... |
|
#3
|
||||
|
||||
|
HTML Code:
<input type="text" id="field_1" name="field_1" maxlength="5" />
<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. |
|
#4
|
|||
|
|||
|
great stuff guys... thanks so much for the info on maxlength
...
|
|
#5
|
|||
|
|||
|
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... |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
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">) |
|
#9
|
||||
|
||||
|
<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. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|