Check if a (String) variable is well defined - use preprocessor?
No, I do not believe this is possible at the preprocessor level. The C preprocessor cannot inspect strings.

If you were to abandon the Arduino IDE and use a Makefile or shell script, you could do it there.

Something along the lines of:

PASSWORD="test"

if [ echo $PASSWORD | grep -e &lt;magic regexp for invalid chars&gt; ]
then
gcc ... -DPASSWORD="$(PASSWORD)"
else
exit 1
fi


Another way might be:

typedef enum
{
MY_A 'a',
MY_B 'b',
MY_C 'c',
// etc. for all allowed characters
} my_charset;

const my_charset *password = {MY_P, MY_A, MY_S, MY_S, MY_W, MY_O, MY_R, MY_D};