Tagged: BP Username Changer, validation
Hi,
How can we add a custom BP error validation to the username?
I need to make it alphanumeric and minimum of 5 chars.
Please, advise.
Hi Renato,
Thank You for posting. You can create a custom error message by using the following code in your bp-custom.php file
add_filter('bp_username_changer_validation_errors', 'buddydev_username_changer_custom_error_message', 3, 2 ); function buddydev_username_changer_custom_error_message( $error, $new_user_name ) { if ( ! is_numeric( $new_user_name ) ) { $error = new WP_Error( 'invalid', __( 'Username name must be numeric', 'bp-username-changer' ) ); } if ( strlen ( $new_user_name ) < 5 ) { $error = new WP_Error( 'invalid', __( 'New user name can not be less than five character', 'bp-username-changer' ) ); } return $error; }
Thank You
RaviHi Ravi, thank you for the prompt response.
But !is_numeric will allow ALPHANUMERICS only?
We want to avoid symbols etc.
Thank you,
Hi Renato
Please try this
add_filter('bp_username_changer_validation_errors', 'buddydev_username_changer_custom_error_message', 3, 2 ); function buddydev_username_changer_custom_error_message( $error, $new_user_name ) { if ( ! ctype_alnum ( $new_user_name ) ) { $error = new WP_Error( 'invalid', __( 'Username name must be alphanumeric', 'bp-username-changer' ) ); } if ( strlen ( $new_user_name ) < 5 ) { $error = new WP_Error( 'invalid', __( 'New user name can not be less than five character', 'bp-username-changer' ) ); } return $error; }
Thank You
RaviHi Ravi, the alphanumeric check worked, but the translation for the ERRORS did not.
We just downloaded the 1.2.2 and add the custom original and translated error string in the PO file.
Could you please advise?
Yes, I managed to load the pot, it was a mistyping. Thank you!
You must be logged in to reply to this topic.