Actually, I originally wanted to use regular expressions to check when creating such a script, but faced the difficulty of building a regex and the confusion of implementing this idea. In addition, provided that for some special characters it is necessary to use escaping these characters with a backslash "\" and also follow some other regex rules, this can cause difficulties and questions for most users when editing and configuring the script. It is also likely that some users, for some reason, may need to use only a certain limited set of characters, maybe not even the entire English alphabet (or mixed with other national characters) and also possibly not with all numbers, etc. Therefore, I decided to do it easier, to the detriment of efficiency, but with the ability to manually enumerate all the necessary symbols to resolve them in messages.
Nevertheless, I will try to figure it out with this, to would improve the script and make it more efficient, taking into account your useful advice and recommendations.
Thanks to you for the sufficiently meaningful capacious post and a detailed explanation of how to use $regex. Undoubtedly, this information will be useful both to me and to many other scripters.