TOPIC:

How To Validate? 7 months 1 week ago #238629

  • Topic Author
  • wa3riz
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 30
  • Thanks: 0
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

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

How To Validate? 7 months 1 week ago #238635

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

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

How To Validate? 7 months 6 days ago #238640

  • Topic Author
  • wa3riz
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 30
  • Thanks: 0
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

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

How To Validate? 7 months 6 days ago #238652

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

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

How To Validate? 7 months 5 days ago #238660

  • Topic Author
  • wa3riz
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 30
  • Thanks: 0
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?

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

How To Validate? 7 months 4 days ago #238665

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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
The following user(s) said Thank You: wa3riz

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

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

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!