1. Help Center
  2. Python Programming

Can you easily check if all characters in the given string is alphanumeric?

This can be easily done by making use of the isalnum() method that returns true in case the string has only alphanumeric characters.
 
For Example -
 
"abdc1321".isalnum() #Output: True
"xyz@123$".isalnum() #Output: False
Another way is to use match() method from the re (regex) module as shown:
 
import re
print(bool(re.match('[A-Za-z0-9]+$','abdc1321'))) # Output: True
print(bool(re.match('[A-Za-z0-9]+$','xyz@123$'))) # Output: False