TOPIC:

Simple Validation for URL 1 year 6 months ago #233405

  • osmosisinc's Avatar Topic Author
  • osmosisinc
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 34
  • Thanks: 0
Hi! I would like to validate a textfield to have a url like address.com or address.com . I found code to prevent a URL (below) can you help me change it to accept a URL only? Thank you!
function ff_fieldname_validation(element, message)
{   var urlRegex = /(https?:\/\/[^\s]+)/g;
    if ( urlRegex.test(element.value) ) {
        if (message=='') message = "A hyperlink was entered! \n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_fieldname_validation

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

Simple Validation for URL 1 year 6 months ago #233450

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

If I understood correctly, you have code to prevent url form being submitted, but you want to modify it so that it checks that URL is what is being submitted.

Here is the code that will validate filed and check whether URL was entered:
function ff_fieldname_validation(element, message)
{   var urlRegex = /(https?:\/\/[^\s]+)/g;
    if ( ! (urlRegex.test(element.value)) ) {
        if (message=='') message = "Please enter URL! \n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
} // ff_fieldname_validation

Let me know whether it works as you wanted.

Regards,

Mihaela

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

Simple Validation for URL 1 year 3 months ago #235545

  • Eddy.vh's Avatar
  • Eddy.vh
  • Offline
  • Gold Breezer
  • Gold Breezer
  • Posts: 384
  • Karma: 4
  • Thanks: 62
Hi Mihaela

Is it not possible to save this script in the script library of BF to be able to use it in all the URL fields of all forms created?

I did some tests by taking example on other validation scripts but the submission is inactive.

I suppose a subtle mistake is the reason.

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

Simple Validation for URL 1 year 3 months ago #235563

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

It is possible to save this script in the script library of BF to be able to use it in all the URL fields of all forms created.

To do so, go to BreezingForms > Manage Scripts. There click on new and fill in the fields like in the picture below.


Let me know whether you have managed to write the script so that you can use it for validating form fields.

Regards,

Mihaela
Attachments:

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

Simple Validation for URL 1 year 3 months ago #235576

  • Eddy.vh's Avatar
  • Eddy.vh
  • Offline
  • Gold Breezer
  • Gold Breezer
  • Posts: 384
  • Karma: 4
  • Thanks: 62
Hi Mihaela.

This is actually the code I inserted in my validation script.
If I create a text field to receive a URL and give it the validation FF :: ff_validURL and validate without entering any text, I do not have an error message and whatever happens, the button submission is inoperative.
Attachments:

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

Simple Validation for URL 1 year 3 months ago #235577

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

This script should show an error message
Please enter URL!
in case no value is entered in that field.

I think I see where is the cause of this not working form your screenshot. Now I've noticed that the name of the script is "ff_validURL" while the function that you have defined is "ff_valideURL".

Function and script name must be the same.
Please try to adjust this and let me know whether after that the script is working properly.

Regards,

Mihaela

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

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.110 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

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!