# Write a Python program to Check if String Contain Only Defined Characters using Regex 
 # _importing module
import re
  
  
def check(str, pattern):
    
    # _matching the strings
    if re.search(pattern, str):
        print("Valid String")
    else:
        print("Invalid String")
  
# _driver code
pattern = re.compile('^[1234]+$')
check('2134', pattern)
check('349', pattern)