Sanitization of register_setting()

You can use sanitize_text_field exactly as you are. From the function’s documentation:

  • Checks for invalid UTF-8,
  • Converts single < characters to entities
  • Strips all tags
  • Removes line breaks, tabs, and extra whitespace
  • Strips percent-encoded characters

sanitize_text_field() is already defined as a function in WordPress, so you don’t need to change anything. The sanitize_callback parameter takes a function name; only if you want to do custom sanitization would you need to define a new function.