1

I'm trying to validate input field in Magento 2. I have added js to same page, so validation like this data-validate="{required:true, 'validate-email':true}" works.

But how to validate min_text_length or max-words or something that requires number, not just true or false?

This is how I tried but it does not work.

<input value="Name" name="first_name" id="first_name_field" class="input-text" data-validate="{required:true, 'min_text_length':'20'}" type="text">

2 Answers 2

0

You can try the below code.

Only added 'validate-length':true in the tag.

<input value="Name" name="first_name" id="first_name_field" class="input-text" data-validate="{required:true,'validate-length':true, 'min_text_length':'20'}" type="text">

OR

<input value="Name" name="first_name" id="first_name_field" data-validate="{required:true, 'validate-length':true}" class="validate-length minimum-length-[0-9]+$ maximum-length-[0-9]+$ input-text" type="text" />
1
  • Unfortunately, it does not work Commented Jun 28, 2017 at 18:00
0

Turns out it is a bug of Magento 2. I'm currently on Magento CE 2.1.7 and this bug is not fixed, and the solution is exactly in this discussion:

Magento 2 minimum length validation is not working for text field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.