Home › Forums › General Issues › Removing Non-Numeric Characters from ACF Form › Reply To: Removing Non-Numeric Characters from ACF Form
I tried two things:
1. I put it at the end of my main WordPress functions.php file.
2. I put it in the __construct function of the plugin file I am working with (the main plugin.php) file. For context, it looks like this. Note: I’ve replaced the actual plugin name with a generic “plugin” name.
File: plugin.php
Code:
<?php
/**
* @package Plugin
* @version 1.0.0
*/
/*
Plugin Name: Plugin
Plugin URI: https://plugin.com/
Description: Plugin Description
Author: Me
Version: 1.0.0
Author URI: https://plugin.com/
*/
class plugin
{
public static $version = '';
/**
* pluginconstructor.
*
* The main plugin actions registered for WordPress
*/
public function __construct()
{
add_filter(‘acf/validate_value/name=sell_price’, ‘allow_only_floats’, 20, 4);
add_filter(‘acf/validate_value/name=buy_price’, ‘allow_only_floats’, 20, 4);
function allow_only_floats($valid, $value, $field, $input) {
if (!$valid) {
return $valid;
}
if (preg_replace(‘/[^0-9.]/’, $value)) {
return ‘Only numbers are accepted’;
}
return $valid;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.