import re
def checkvalid(string1):
if re.search(r'[d.]s+[d.]', string1): return False # two numbers separated by spaces
string1 = string1.replace(' ', '')
return (bool(re.search(r'd', string1)) # must contain numbers
and not re.search(r'.d*.', string1) # a number can't contain two dots
and not re.search(r'[$^]{2}|#[$^]|[$^]#[$^#]', string1) # obviously
and not re.search(r'^[$^]|[$^]$', string1) # special at the beginning or end
and not re.search(r'^##|##$', string1) # two hashes at the beginning or end
)