xPDOMinLengthValidationRule
Last updated Oct 17th, 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 verifies that the field is at least X characters long, where X is the value attribute in the schema. If value is omitted, X is 0 and only a non-string value fails.
The field the rule is attached to must be declared in the same object, and the value being checked must be a string: a numeric field fails this rule regardless of its value.
Using the Rule¶
First, our model:
<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="name" dbtype="varchar" precision="255"
phptype="string" default="" null="false" />
<validation>
<rule field="name"
name="myMinLenRule"
type="xPDOValidationRule"
rule="xPDOMinLengthValidationRule"
value="1"
message="Please specify a name."
/>
</validation>
</object>
</model>
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('name','');
$validator = $obj->getValidator();
if (!$validator->validate()) {
foreach ($validator->getMessages() as $errorMsg) {
$output .= $errorMsg['message'];
}
}
return $output;
This will display:
Please specify a name.
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










