How To Validate?

  • wa3riz
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0

wa3riz created the topic: How To Validate?

How do I validate that a text field contains only a-z, A-Z, ?!&, and 0-9?
I am trying to put more restrictions on a textfield than what I suspect is the default.
I would prefer that the field simply ignores them on input, but validating when the Submit button is pushed is acceptable.

Thank you, Jeff
#238629
  • Posts: 2785
  • Karma: 95
  • Thank you received: 376

mihaela replied the topic: How To Validate?

Hello,

If I have understood correctly, you would like that all input characters which are different from a-z, A-Z, ?!&, and 0-9 are deleted as they did no exist in the input.

Would it be acceptable for you that user gets notified if he enters something different from a-z, A-Z, ?!&, and 0-9 so that he can correct the input?

Regards,

Mihaela
#238635
  • wa3riz
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0

wa3riz replied the topic: How To Validate?

Mihaela

Yes, you understand correctly. Yes, it would be preferred that the user
be notified as they type and enter an incorrect character.

Thank you, Jeff
#238640
  • Posts: 2785
  • Karma: 95
  • Thank you received: 376

mihaela replied the topic: How To Validate?

Hello,

Here is a solution that will change the value entered in the field on submission in a way that all characters different from a-z, A-Z, ?!&, and 0-9 are deleted.

Go to the Properties of that field in your form. In the "Validation" section check the Required checkbox and set Type to Custom. Then in the code area below put the following code:
function ff_fieldname_validation(element, message)
{
    element.value = element.value.replace(/[^0-9a-z-A-Z!?& ]/g, "").replace("-","");
    console.log(element.value);
    return '';
} // ff_fieldname_validation
NOTE: Replace the fieldname with the Name of that field in your form.

That will do the trick when a user submits the form, unallowed characters will be deleted.

As for notifying the user about the wrong entry on trying would require a Custom solution. If you wish to implement that, this guideline might help you crosstec.org/en/forums/3-breezingforms-f...extfield.html#233600 .


Regards,

Mihaela
#238652
  • wa3riz
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0

wa3riz replied the topic: How To Validate?

Mihaela,

This works. Thank you. But, I must have misunderstood your confirmation. I'm looking to simply show an error message when user hits Submit.

You gave the following script to someone and it does basically what I need.
Except, I need to specify [^0-9a-z-A-Z ] as allowed. Simplified to only letters,numbers, and space.
function ff_FIELDNAME_validation(element, message)
{
if (element.value == "xy") {
if (message=='') message = element.name+" faild in my test.\n"
ff_validationFocus(element.name);
return message;
} // if
return '';
} // ff_FIELDNAME_validation

I can't figure out what to replace that element.value == "xy" with to error on any non valid character upon submit. Is this PHP or Javascript?
#238660
  • Posts: 2785
  • Karma: 95
  • Thank you received: 376

mihaela replied the topic: How To Validate?

Helo again,

Ok, I've misunderstood you.

Here is the code that will notify the user about the wrong input:
function ff_FIELDNAME_validation(element, message)
{  
    var regex = /^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/;
    if(!regex.test(element.value)) {

        element.value = element.value.replace(/[^0-9a-z-A-Z\s ]/g, "").replace("-","");


        if (message=='') message = 'The entered text contains not allowed characters';
        ff_validationFocus(element.name);
        return message;
    }
    return '';
} // ff_FIELDNAME_validation
This code will also correct the input(remove unallowed characters). In case you do not want the code to do that, just remove this line:
element.value = element.value.replace(/[^0-9a-z-A-Z\s ]/g, "").replace("-","");

Let me know whether this is working as you wanted.

Regards,

Mihaela
#238665
The following user(s) said Thank You: wa3riz
Moderators: ForumSupporttomeperica
Time to create page: 0.066 seconds

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!

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 and icon packs!

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