Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

max/min characters allowed

Featured Replies

I was wondering how i could set a max (500) and min (20) characters allowed for my posting/message system.

 

code for this

    <div class='submit'>
   <form method="post" action="newthread.php">LAD Name: 
<input name="author"/><br/>Message:<br/>
<textarea rows="5" cols="60" name="message"></textarea><br/>
<input value="Post Banter" type="submit"/> </form>
</div>

 

PLEASE NOTE I CAN NOT CHANGE 'NAME' AS IT BREAKS MY PHP CODE FOR POSTING TO DATABASE

 

i tried a script i found on net but when i used this it broke my writing to database.

 

So can someone please tell me how i can set max/min characters allowed and to display error message if these are not met

I was wondering how i could set a max (500) and min (20) characters allowed for my posting/message system.

 

code for this

    <div class='submit'>
   <form method="post" action="newthread.php">LAD Name: 
<input name="author"/><br/>Message:<br/>
<textarea rows="5" cols="60" name="message"></textarea><br/>
<input value="Post Banter" type="submit"/> </form>
</div>

 

PLEASE NOTE I CAN NOT CHANGE 'NAME' AS IT BREAKS MY PHP CODE FOR POSTING TO DATABASE

 

i tried a script i found on net but when i used this it broke my writing to database.

 

So can someone please tell me how i can set max/min characters allowed and to display error message if these are not met

 

try

<textarea rows="5" cols="60" maxlength="500" name="message"></textarea>

 

im not too sure whether minlength is something you could apply to a input field, check the length using php :)

Edited by web-itec

  • Author

try

<textarea rows="5" cols="60" maxlength="500" name="message"></textarea>

 

im not too sure whether minlength is something you could apply to a input field, check the length using php :)

 

This doesnt do anything. I tested it with a short value and text was still inputted to database

maxlength is an attribute of INPUT not TEXTAREA.

 

You need to code some javascript magic to add a maxlength to TEXTAREA and minlength to either INPUT and TEXTAREA.

 

Do a google for the bassistance jQuery validation plugin which does exactly what you need with little effort.

Size and cols for form input and textarea code limits the size of the box on the screen. The user's input can be any length unless you use PHP to code the form and then you can limit the characters. It would be something like

$wordcount = str_word_count($message); 
if ($wordcount >50) {
echo "Please do not exceed fifty words.";
}

for counting words or another code for characters. The above would have to be tailored to suit a PHP form and might use else or elseif and we don't know what the rest of your PHP process code is.

Edited by Wickham

Size and cols for form input and textarea code limits the size of the box on the screen. The user's input can be any length unless you use PHP to code the form and then you can limit the characters. It would be something like

$wordcount = str_word_count($message); 
if ($wordcount >50) {
echo "Please do not exceed fifty words.";
}

for counting words or another code for characters. The above would have to be tailored to suit a PHP form and might use else or elseif and we don't know what the rest of your PHP process code is.

 

 

Something like this IMO would be better done on client side, then backed up on server side.

 

I'd be pissed off if I spent 10 minutes filling in a textarea submitting the form and then being told I was only supposed to write 10 chars.

 

Also I think the OP is looking to count letter count, not word count.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.