TOPIC:

Validation (PHP) 3 years 5 months ago #227260

  • Topic Author
  • jasondawdy0503
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 53
  • Thanks: 0
Good afternoon folks. I am trying to figure out how I would go about writing a validation code for Content Builder (Not Breezing Forms) that will not allow them to enter anything other then a 5 digit number in the zip code field. No letters, no dashes, no 2 digit numbers. any ideas?

Please Log in or Create an account to join the conversation.

Validation (PHP) 3 years 5 months ago #227273

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello,

So you didn't create a Contentbuilder View based on BreezingForms form?

If you are not, to to achieve what you want please follow this steps:

1) Go to the wanted view. Go to View tab and in the Editable column click on [text] of the wanted element.

2) Go to Scripts tab and in the Init (JS) section in the Init Code textarea write the following code:
var el = jQuery(contentbuilder._("fieldname")).on('change', function(){
var regex = /^\d{1,5}$/;
    if( !regex.test( jQuery(this).val())  ){
       jQuery(this).before('<div class="first" style="color:red">Field must contain a 5 digits number.</div>');
       contentbuilder.onSubmit( function() { return false; } )
    }
else {
   jQuery(".first").remove();
   contentbuilder.onSubmit( function() { return true; } )
   }
});
NOTE: In the code above replace fieldname with the Name of the field for zip code.

Let me know if this works how you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Validation (PHP) 3 years 5 months ago #227316

  • Topic Author
  • jasondawdy0503
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 53
  • Thanks: 0
It worked splendidly for blocking anything but numbers. Is there a way to alter it so they can just put in 57. I want to force a 5 digit number like 57645

Thank you

Please Log in or Create an account to join the conversation.

Validation (PHP) 3 years 5 months ago #227342

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Hello again,

If I understood you correctly you want to allow the submitter to enter only 5 digits number that starts with numbers 57.

If that is what you wanted here is the code that will make that possible:
var el = jQuery(contentbuilder._("fieldname")).on('change', function(){
var regex = /^\d{1,5}$/;
var  tmp = jQuery(this).val();
var firsttwo  = tmp.substring(0, 2);
    if( !regex.test( tmp)  || tmp.length != 5 || firsttwo !='57'){
       jQuery(this).before('<div class="first" style="color:red">Field must contain a 5 digits number starting with 57.</div>');
       contentbuilder.onSubmit( function() { return false; } )
    }
else {
   jQuery(".first").remove();
   contentbuilder.onSubmit( function() { return true; } )
   }
});
NOTE: In the code above again replace fieldname with the Name of zip code field in your form.
Also, you can replace "Field must contain a 5 digits number starting with 57." with the message that you find most appropriate.

Let me know if this is what you wanted to achieve.
If you have more questions, feel free to ask.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Validation (PHP) 3 years 5 months ago #227369

  • Topic Author
  • jasondawdy0503
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 53
  • Thanks: 0
You folks are great as always. Worked perfectly. Thanks,

Please Log in or Create an account to join the conversation.

Validation (PHP) 3 years 5 months ago #227395

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 415
Thank you for the kind words. :)

I'm glad I've helped.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.049 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!