my_str.isalnum())
Checks for alphanumeric characters in a string. Returns True if only number and alphabets are present and returns False if any thing other than alphanumeric characters are present.
my_str='plus2net'
print(my_str.isalnum()) # Output is True
my_str='Welcome to plus2net'
print(my_str.isalnum()) # Output is False (presence of Space)
More using special chars
print('plus2net'.isalnum()) # True 2 is allowed
print('_plus2net'.isalnum()) #False _ not allowed
print('plus_2net'.isalnum()) #False _ not allowed
print('plus.2net'.isalnum()) #False . not allowed
print('plus-2net'.isalnum()) #False - not allowed
print('plus@2net'.isalnum()) #False @ not allowed
print('plus#2net'.isalnum()) #False # not allowed
print('plus 2net'.isalnum()) #False space not allowed
if(len(userid) <5 or len(userid)>12 or not userid.isalnum()):
flag_validation=False
Read the full script at Login Registration system. Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.