How can I add a leading zero to 4-digit numbers in search inputs?

Topic summary

A user needed to automatically prepend a leading zero to 4-digit search inputs in their Shopify store (e.g., converting “5600” to “05600” before submission).

Problem Context:

  • The search form uses a standard /search action with a q parameter
  • The value needed modification before being submitted to the search engine

Solution:
The original poster resolved the issue using jQuery to intercept and modify the search value before form submission. The implementation checks the input value and prepends a zero to 4-digit numbers as needed.

Status: Resolved - the user successfully implemented the fix themselves.

Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

Can I change the submitted value for search
I need to add a leading zero to for 4 digit numbers

For example someone inputs
5600
The search engine looks for
05600

<form action="/search">
  <input type="text"
    placeholder="Search"
    name="q" // Change this value before submission or before it sends to /search
  />
  <input type="hidden" name="type" value="product,page" />
  <input type="hidden" name="options[unavailable_products]" value="hide" />
  <input type="hidden" name="options[prefix]" value="last" />
  <input type="submit" value="Search" />
</form>

Hi @scs-accounts ,

Which theme are you using? You will probably be able to prepend the value to the search parameter in the liquid files.

I solved it

I used jquery for this

Right before submission I can check the value and modify it