Magento 2 Validation Rules List


Here is list of validations classes rules supported by magento 2. You just need to add css class for the rule to apply.

  1. min_text_length
  2. max_text_length
  3. max-words
  4. min-words
  5. range-words
  6. letters-with-basic-punc
  7. alphanumeric
  8. letters-only
  9. no-whitespace
  10. zip-range
  11. integer
  12. vinUS
  13. dateITA
  14. dateNL
  15. time
  16. time12h
  17. phoneUS
  18. phoneUK
  19. mobileUK
  20. stripped-min-length
  21. email2
  22. url2
  23. credit-card-types
  24. ipv4
  25. ipv6
  26. pattern
  27. validate-no-html-tags
  28. validate-select
  29. validate-no-empty
  30. validate-alphanum-with-spaces
  31. validate-data
  32. validate-street
  33. validate-phoneStrict
  34. validate-phoneLax
  35. validate-fax
  36. validate-email
  37. validate-emailSender
  38. validate-password
  39. validate-admin-password
  40. validate-url
  41. validate-clean-url
  42. validate-xml-identifier
  43. validate-ssn
  44. validate-zip-us
  45. validate-date-au
  46. validate-currency-dollar
  47. validate-not-negative-number
  48. validate-zero-or-greater
  49. validate-greater-than-zero
  50. validate-css-length
  51. validate-number
  52. validate-number-range
  53. validate-digits
  54. validate-digits-range
  55. validate-range
  56. validate-alpha
  57. validate-code
  58. validate-alphanum
  59. validate-date
  60. validate-identifier
  61. validate-zip-international
  62. validate-state
  63. less-than-equals-to
  64. greater-than-equals-to
  65. validate-emails
  66. validate-cc-number
  67. validate-cc-ukss
  68. required-entry
  69. checked
  70. not-negative-amount
  71. validate-per-page-value-list
  72. validate-new-password
  73. validate-item-quantity
  74. equalTo

You can see that email_from , I have given ‘class’ => ‘validate-email’ for email validation

protected function _prepareForm()
{

       $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' =>  $this->getData('action'), 'method' => 'post']]
        );

        $form->setHtmlIdPrefix('post_');

$fieldset = $form->addFieldset(
            'base_fieldset',
            ['legend' => __('Form Information'), 'class' => 'fieldset-wide']
        );

  $fieldset->addField(
            'email_from',
            'text',
            ['name' => 'email_from', 'label' => __('Email From'), 'title' => __('Email From'), 'required' => true,'class' => 'validate-email']
        );
        
 $form->setValues($model->getData());
        $form->setUseContainer(true);
        $this->setForm($form);

        return parent::_prepareForm();
    }