isalnum()

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

Validating userid

In any signup or login form , the userid input is to be checked then isalumn() function can be used.
Here is a code which checks the length and if the input string and is alphanumeric or not. If any condition fails then the flag used for checking became False.
if(len(userid) <5 or len(userid)>12 or not userid.isalnum()):
            flag_validation=False 
Read the full script at Login Registration system.
All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer