xPDOMinValueValidationRule
Last updated Oct 20th, 2026 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn moreWhat Does the Rule Do?¶
This rule compares the numeric value of a field with a minimum given by the value attribute in the schema.
[!CAUTION]
xPDOMinValueValidationRulenever fails validation in xPDO 3.x. ItsisValid()method computes the comparison and adds the message, but does not return the result, so the rule scores as passed.xPDOValidator::validate()returnstrueeven when the minimum is not met.The message is still written to
getMessages(), so a caller that inspects the messages unconditionally sees it, while a caller that only checks the return value ofvalidate()does not. Use thecallablerule below instead if you need a minimum.
Without value, the minimum defaults to 0.
Working Alternative: a callable Rule¶
Declare the minimum as a callable rule, which returns its result correctly:
<model package="Test" baseClass="xPDO\Om\xPDOObject" platform="mysql"
defaultEngine="InnoDB" version="3.0">
<object class="myTest" table="test" extends="xPDO\Om\xPDOSimpleObject">
<field key="number" dbtype="int" precision="10"
phptype="integer" default="0" null="false" />
<validation>
<rule field="number"
name="myMinValRule"
type="callable"
rule="StoreFinder\Model\Validation\myMinValue"
value="20"
message="The number must be at least 20."
/>
</validation>
</object>
</model>
The rule attribute must be fully qualified, because a bare name is resolved against the xPDO\Validation\ namespace.
<?php
namespace StoreFinder\Model\Validation;
class myMinValue {
public function __invoke($value, $parameters) {
return $value >= (int) $parameters['value'];
}
}
Generate the model from the XML schema, then validate an object in a Snippet:
$output = '';
$modx->addPackage('Test', '/path/to/components/test/model/');
$obj = $modx->newObject('Test\myTest');
$obj->set('number', 12);
$validator = $obj->getValidator();
if (!$validator->validate()) {
foreach ($validator->getMessages() as $errorMsg) {
$output .= $errorMsg['message'];
}
}
return $output;
This will display:
The number must be at least 20.
See Also¶
- xPDOForeignKeyConstraint
- xPDOMaxLengthValidationRule
- xPDOMaxValueValidationRule
- xPDOMinLengthValidationRule
- xPDOMinValueValidationRule
- xPDOObjectExistsValidationRule
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn more










