function DecimalItem::getConstraints

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem::getConstraints()

Overrides NumericItemBase::getConstraints

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php, line 93

Class

DecimalItem
Defines the 'decimal' field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function getConstraints() {
  $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
  $constraints = parent::getConstraints();
  $constraints[] = $constraint_manager->create('ComplexData', [
    'value' => [
      'Regex' => [
        'pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i',
      ],
    ],
  ]);
  return $constraints;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.