[Answered ]-Python alphanumeric Validation server side using regular expression

0πŸ‘

βœ…

You have miss placed the argument in method reverse it .

it will work.

But this also matched if you set symbol in your string.
so, i suggest you apply this things :

pwd =”test5456β€³

pwd.isalnum():

This method will only work for if your string contain string or digit.

if you want strongly want your password contain both numeric and string than this code will help you.

 test = "anil13@@"
 new = tuple(test)
 data = list(new)
 is_symb =False
 is_digit = False
 is_alpha = False

 for d in data :
    if d.isdigit() :
       is_digit = True
    if d.isalpha():
       is_alpha = True
    if not d.isdigit() and not d.isalpha():
       is_symb =True
       break
if is_symb == False and is_digit == True and is_alpha == True:
   print "pwd matchd::::"
else :
   print "pwd dosen't match..."

Note :This code strongly work for numeric & symbol

Regards,
Anil

πŸ‘€Anil Kesariya

2πŸ‘

You reversed the arguments of match

re.match(pattern, string, flags=0)

It should be

match  = re.match(num, pwd)
πŸ‘€iabdalkader

1πŸ‘

You can do this to find out if the string is alphanumeric

pwd = "asdf67AA"
if pwd.isalnum():
    # password is alpha numeric
else:
    # password is not alpha numeric
πŸ‘€Rag Sagar

0πŸ‘

This is very simple answer and it is better to use regex for validation instead of wired if else condition.

import re
password = raw_input("Enter Your password: ")
if re.match(r'[A-Za-z0-9@#$%^&+=]{6,}', password):
    print "Password is match...."
else:
    print "Password is not match...."
#6 means length of password must be atleast 6
πŸ‘€Heroic

-1πŸ‘

you can do it by using isalnum() method of python
just by doing

pwd.isalnum()

it will tell wthether a number is alphanumeric or not and then will hit the if condiion

πŸ‘€S.Ali

Leave a comment