Apply custom validation to a field

You can use UM action hooks to apply custom validations and rules for any fields and stop form from being submitted until the conditions are met. In this example, we check that the username field does not have the word admin.

add_action('um_submit_form_errors_hook_','um_custom_validate_username', 999, 1);
function um_custom_validate_username( $args ) {
	if ( isset( $args['user_login'] ) && strstr( $args['user_login'], 'admin' ) ) {
		UM()->form()->add_error( 'user_login', 'Your username must not contain the word admin.' );