Simple Validation for URL

  • osmosisinc
  • osmosisinc's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 34
  • Thank you received: 0

osmosisinc created the topic: Simple Validation for URL

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
#233405
  • Posts: 2365
  • Karma: 85
  • Thank you received: 317

mihaela replied the topic: Simple Validation for URL

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
#233450
  • Eddy.vh
  • Eddy.vh's Avatar
  • Away
  • Expert Boarder
  • Expert Boarder
  • Posts: 158
  • Karma: 1
  • Thank you received: 14

Eddy.vh replied the topic: Simple Validation for URL

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.
#235545
  • Posts: 2365
  • Karma: 85
  • Thank you received: 317

mihaela replied the topic: Simple Validation for URL

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
#235563
Attachments:
  • Eddy.vh
  • Eddy.vh's Avatar
  • Away
  • Expert Boarder
  • Expert Boarder
  • Posts: 158
  • Karma: 1
  • Thank you received: 14

Eddy.vh replied the topic: Simple Validation for URL

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.
#235576
Attachments:
  • Posts: 2365
  • Karma: 85
  • Thank you received: 317

mihaela replied the topic: Simple Validation for URL

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
#235577
Moderators: ForumSupporttomeperica
Time to create page: 0.215 seconds

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans & templates!

Get Your Subscription Here

News and Updates

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

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

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!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here