in the number field has the option of adding and subtracting, how do I disable it?
This is a feature of browsers automatically added to number fields and is not something that ACF creates. As far as I know there isn’t a way to remove it. You’d need to use a text field and add your own validation to make sure only numbers are added.
I understood!
And how do I verify that they can only enter numbers?
https://www.advancedcustomfields.com/resources/acf-validate_value/
add_filter('acf/validate_value/name=your-field-name', 'validate_text_as_number', 20, 4);
function validate_text_as_number($valid, $value, $field, $input) {
if ($valid !== true) {
return $valid;
}
if (preg_match('/[^0-9]/', $value) {
$valid = 'enter only numbers';
}
return $valid;
}
I’m getting an error on:
$valid = 'enter only numbers';
why?
thank you
Missing ) on the line above should be if (preg_match('/[^0-9]/', $value)) {
Can I apply this filter to several fields at a time?
Or you have to copy it on each field separately
just add additional lines for each field with each field name
add_filter('acf/validate_value/name=your-field-name', 'validate_text_as_number', 20, 4);