cformsII Support Forum
Current User: Guest *Frequently Asked Questions*
Search 
Search Forums:


 




Character limit verification

Add a New Topic Reply to Post
Post

Jim - Guest

8:32 pm - April 8, 2008

Please replace the ??? with your data!


[desc]:

The option to add character limits in Cforms is great, but it would be really sweet if you were able to make it stop at the maximum number of characters allowed. While the current method (along with instructions for the user) works for 99% of our clients, that other 1% just get confused that the box does not get rid of the red border once they reduce the characters. If you were able to get it to monitor the # of characters as the user is typing, and cut it off at the max, that would be great. Unfortunately some of our clients need something braindead simple since they aren't too computer saavy. Just a thought.

Thanks,

Jim

Oliver - Admin

9:08 pm - April 8, 2008

posts 3549

Jim, this is quite easy to do and I'm not sure it makes sense to add it to the core Javascript library.

Also note, that if someone turns off Javascript then there is no real-time character limit whatsoever.

This is what I would do:

  1. deploy jQuery
  2. attach a function count_chars() to the respective input field/textarea (change event, key event)
  3. within count_chars() of course you count all characters of the given input field and in case the limit is reached, you clear the last key stroke)

The function shouldn't be more than 3-4 lines...

Jim - Guest

5:34 pm - April 10, 2008

Thanks for the reply, Oliver. That seems over my head, but I'll look into it. I actually just noticed with 8.1 (which I just updated to a couple days ago) if the user has entered more than the allowed characters, the form won't send even after reducing the characters to below the max allowed. Even dropping it to four characters wouldn't let it send. Maybe I'm trying to do too much with using CForms as a method for sumbitting classified ads.

-Jim

Oliver - Admin

5:39 pm - April 10, 2008

posts 3549

I noticed that my earlier suggestion for the correct regexp was partially broken (under certain circumstances), can you try this and see if this fixes it:

Your Message|max. # of 150 characters|^[\s\S]{1,170}$

The above I've tested and ought to work properly.

Add a New Topic Reply to Post


Reply to Topic: Character limit verification
PLEASE READ THE FAQs FIRST! THANK YOU.

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 7 + 1        (Required)

Topic Reply:


 
© Simple:Press Forum - Version 3.1.3 (Build 356)