5

How to create custom Validation for UI Component Form? I want to create Validation for maximum character, not for max-word which is already available in Magento 2. if any body knows please share the procedure.Thanks

  • Can you please share your code where you want to add? – Rohan Hapani Aug 1 '18 at 18:02
  • @RohanHapani <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> <item name="validate-length" xsi:type="boolean">true</item> Here i want to limit my character. i want that form sould only accept 250 character . </item> – i_ali55 Aug 1 '18 at 18:13
  • please check my answer and let me know if any issue. – Rohan Hapani Aug 1 '18 at 18:42
7

Try to do like this :

<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
<item name="max_text_length" xsi:type="number">250</item>
</item>

clean cache and check it.

  • thank you, its working. do you know how i can create my own validation? – i_ali55 Aug 1 '18 at 18:50
  • 1
    Happy Coding !! :) You can accept this answer for helpful to other developer. – Rohan Hapani Aug 1 '18 at 18:51
  • Yes. You can create custom validation by js. You can take reference from here. inchoo.net/magento-2/build-your-custom-form-validation-rule – Rohan Hapani Aug 1 '18 at 18:53
  • Now, You can Re-accept answer if this answer is useful in this above question ;) – Rohan Hapani Aug 1 '18 at 19:10
  • 1
    Yes. I can give answer. But, you can create new question for that. Because, what's your question that I already gave answer and it's 100% working as you said. So, you can accept it. It's better if you create new question. So, for other user it's easy to get answer of this question :) – Rohan Hapani Aug 2 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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