Hi,
Could anyone help me in how to validate a text filed. I have a text filed what I want is that shoppers can just enter numbers 0-9 and if they type any letter or other character it give error.
my code is
{% if product.title contains 'Num %}
Enter Plate Number (Max 5 Digits)
abel for=“monogram”>Enter Code
.ep_inline_block {display:inline-block;vertical-align:middle;margin-left:10px;}
.ep_block {display:block;margin-top:10px;margin-bottom:2px;}
{% endif %}
Hello @amazezones
You need to add some validations. Please replace this code (your existing code)
with below code (fresh code with validations)
It will prevent user to enter Alphabets and only allow 5 digits
Thanks
thx its working for me… There is one more thing could you help… Currently shoppers can add to cart without filling the field, how can I make it compulsory…
did you found solution to this?
Hi @amazezones .,
While you have already received a solution, I’d like to offer another user-friendly alternative to create a field for shoppers to enter numbers 0-9 with validation, without requiring any coding. This option can be helpful for you and other members in the future
.
You can achieve this by using the Free version of the Easify Product Options app. Follow these steps to set it up quickly:
- Add a text field using the "Number Text Box" option type provided by the app. You can set the max value to “99999” if customers are allowed to enter up to 5 digits. Optionally, you can add a help text of “Max 5 Digits” to guide customers:
- If customers enter text instead of a number, the app will show an error message:
- Select the products on which you want to display the custom text fields on their product pages, and you’re all set!
As you can see, creating a number text field with the Easify Product Options app is straightforward and efficient. Keep this option in mind for any similar issues in the future
.