Strings and Character

Check Special Character

# ตรวจสอบว่าข้อความดังกล่าวมีไม่มีอักขระพิเศษหรือไม่ (ไม่มี return = True)

# import required package 
import re 
  
# Function checks if the string 
# contains any special character 
def check_special_char(string): 
  
    # Make own character set and pass  
    # this as argument in compile method 
    regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') 
      
    # Pass the string in search  
    # method of regex object.     
    if(regex.search(string) == None): 
        return True 
          
    else: 
        return False 

Last updated