Home › Forums › General Issues › Removing Non-Numeric Characters from ACF Form › Reply To: Removing Non-Numeric Characters from ACF Form
I did that but for some reason it made the field disappear. What I really want to do is to strip non-numeric characters before it is submitted.
I looked at this forum thread that you previously answered before John: https://support.advancedcustomfields.com/forums/topic/limit-field-value-to-letters-only-with-no-numbers/ and it did not work. This is what I did:
1. I placed this code into the __construct function of the main plugin php file (the php file with the same name as the plugin). This is the code:
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;
}
2. When I put in non-numeric characters, it was still being saved with those non-numeric characters.
3. I’m not really sure what the “20” and “4” values mean, but I just copied it from your previous form post.
Where could I go from here?
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.