How can we validate individual form field In Magento 2?

by chirag   Last Updated March 16, 2017 09:09 AM

In Magento 1.x we can validate individual form field like.

<input class="input-text required-entry" id="name" title="First Name" type="text" name="name" value="" onblur="validate(this)"/>

function validate(id){
   Validation.validate(id);
}

In Magento 2.x How can we validate individual form field?

I want to validate only one field from multiple fields in a single form.



Answers 1


<form class="form"
      action="<?php Your Action ?>"
      id="form"
      name="form"
      method="post"
      data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>"
      data-mage-init='{"validation":{}}'
      enctype="multipart/form-data" >
<input type="text" name="title" id="title" title="<?php /* @escapeNotVerified */ echo __('Title') ?>" class="input-text data-validate="{required:true}"  value=""  />
</form>
Ankit Shah
Ankit Shah
March 16, 2017 08:32 AM

Related Questions


Magento 2 checkout input field validation possibility

Updated December 28, 2017 14:09 PM


Adding custom global javascript validation

Updated June 18, 2016 08:03 AM