I usually check if my string only has characters which are valid. In this case you can use:
you can store this regex in a string variable and perform isMatch function on the string. the above regex can be modified based to exclude the special characters
You can find more information about regular expressions on https://docs.mendix.com/refguide/regular-expressions.
The example that Sjoerd provides, is correct for only alphanumeric characters.
You can test the regular expressions on https://regex101.com/
Hope that helps.