Skip Navigation

[Resolved] Is there a way to limit/force the number of characters in a search box?

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 15 replies, has 2 voices.

Last updated by Shane 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1108433

Tell us what you are trying to do?

I'm using Toolset on another website I'm putting together: hidden link The search box needs to be used to search for student IDs. All of the students in the system have a 6 digit student ID. The client only wants one student to ever show up in a search. Which means that someone can't just enter "8" or "111," otherwise every student with an 8 or 111 in their student ID will show up. Is there a way to force a search box to 1) require exactly 6 characters or it won't search and only allow numbers (you can't search for a name, for example)? Thanks.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1108519

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

Could you try this code here and let me know the results.

    jQuery("input[name='wpv_post_search']").attr('minlength','6');
    jQuery("input[name='wpv_post_search']").attr('maxlength','6');

Thanks,
Shane

#1108521
Edit_View_‹_Fairmont_International_School_—_WordPress.png

Thank you for responding. Is this where I put the jquery code? (see attached)

Also, is there a way to give the search input field an ID?

#1108527

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Shirink,

Yes this is the correct area.

I just want to see if it will work. I suspect more code is needed tho.

Thanks,
Shane

#1108528

I tried the code. It doesn't look like it's working.

#1108544

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Would you mind allowing me to have admin access to work on this code some more ?

The private fields have been enabled for your next response.

Thanks,
Shane

#1109481

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I believe the we can workaround this by not using the AJAX submit.

Is it a requirement to have the Ajax form submit? Also I noticed that your results are not returning anymore. Did you make any recent changes?

Please let me know.

Thanks,
Shane

#1109584

Ok. What should I do at this point? I didn't change anything. All of the students are still in the system.

#1109648

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I'm currently checking on this for you to see what is wrong.

#1109651

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I've managed to solve the issue and it should be working now.

Thanks,
Shane

#1109680

I just refreshed the page. The search box is still letting me enter any number. Also, if the search box is empty and I hit Submit, all of the records are displayed (which is a big security problem - we don't want parents to be able to see all of the student information).

#1109714

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I've disabled the AJAX search and you should see the restrictions implemented.

Thanks,
Shane

#1109717

Great. Thanks. I'm seeing the character requirement. I have two more changes that I'm hoping are possible. I put a video together to better illustrate what I'm needing to happen. Thanks!

hidden link

#1109731

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I did another adjustment to the code to set a hard limit. This means that the user is not able to click the submit button unless there are 6 digits.

I'm still working on the limiting to number only.

Thanks,
Shane

#1110177

I appreciate your help. Let me know if you've figured out a way to limit it to numbers only. Thanks.