Validate textfield max 7 characters or empty

  • michiel@TSS
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 102
  • Thank you received: 0

michiel@TSS created the topic: Validate textfield max 7 characters or empty

Hello,

I'm trying to make a validation for a text field the can be empty OR has a max of 7 characters. I know how te set max characters... but don't know how to do this.

Hope you can help ;)
Regards,
Michiel
#240431
  • TheMuffinMan
  • TheMuffinMan's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: Validate textfield max 7 characters or empty

Hi,

in your form field's settings, please go to validation => check "required" => set "Validation" to "Custom" => Click "Create code framework.

In the resulting code skeleton, replace everything between the opening and closing curly brackets of the function with this:
    var m = encodeURIComponent(element.value).match(/%[89ABab]/g);
    var length = element.value.length + (m ? m.length : 0);

    if (length != '' && length < 7) {
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';

This should do the trick.

I used this way of determining the string length to take UTF8 characters into account btw.

Attached is also a small form that you can download, unzip and then import in Configuration => Package Installer to run it as demo in your BF installation.

File Attachment:

File Name: SevenOrNothing.zip
File Size:6 KB


Hope this helps!

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240434
Attachments:
The following user(s) said Thank You: michiel@TSS
  • michiel@TSS
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 102
  • Thank you received: 0

michiel@TSS replied the topic: Validate textfield max 7 characters or empty

This works perfectly!! Thank you for the good support again!

Regards,
Michiel
#240439
  • TheMuffinMan
  • TheMuffinMan's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: Validate textfield max 7 characters or empty

no problem, anytime.
If you didn't do yet, please make sure to vote for BreezingForms:
extensions.joomla.org/extension/contacts...orms/breezing-forms/

Thank you!

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240440
  • michiel@TSS
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 102
  • Thank you received: 0

michiel@TSS replied the topic: Validate textfield max 7 characters or empty

Hello.. this solution/validation does work fine when I make a new record in BreezingForms... but when I edit the record in Contentbuilder, the validation is ignored?! What am I missing here?
#240639
  • TheMuffinMan
  • TheMuffinMan's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: Validate textfield max 7 characters or empty

Hi,

it should trigger the exact same validation again.
Do you have a link to the ContentBuilder view where I could try editing the values?

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240647
Moderators: ForumSupport
Time to create page: 0.054 seconds

We Are Doing Our Part

Massive discounts on all of our extension subscription plans to help you and your business in these times.

Get Your Subscription Here

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

We are doing our part and support your business with extremely low prices -- For example 6-Months-Subscription for only $9 USD. For as long as necessary.

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!