diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php index c17e725..e9e42de 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php @@ -95,6 +95,25 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state /** * {@inheritdoc} */ + public function getConstraints() { + $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); + $constraints = parent::getConstraints(); + + $constraints[] = $constraint_manager->create('ComplexData', array( + 'value' => array( + 'Regex' => array( + 'pattern' => '/^[0-9]+(\.[0-9]{1,2})?$/i', + ) + ), + )); + + return $constraints; + } + + + /** + * {@inheritdoc} + */ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { $element = parent::fieldSettingsForm($form, $form_state); $settings = $this->getSettings(); diff --git a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RegexConstraint.php b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RegexConstraint.php new file mode 100644 index 0000000..7d476eb --- /dev/null +++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RegexConstraint.php @@ -0,0 +1,32 @@ +