python - django form field regex validation for alphanumeric characters -


this question has answer here:

i have django form, contains password field, want validate field must contain combination of alphabets , numbers.

class authorizationform(forms.form):     email = forms.charfield()     password = forms.charfield(min_length=7) 

i validating password field this:

def clean_password(self):     password = self.cleaned_data['password']     if not re.match(r'^[a-za-z0-9]+$', password):         raise forms.validationerror("password should combination of alphabets , numbers") 

this piece of code isn't working me, allows abcdefghij or 123456789 or abcd123456, want allow abcd123456

regex isn't necessary, can use string functions this:

import string  def validate(password):     letters = set(string.ascii_letters)     digits = set(string.digits)     pwd = set(password)     return not (pwd.isdisjoint(letters) or pwd.isdisjoint(digits))  print(validate('123123'))    # false print(validate('asdfsdf'))   # false print(validate('12312sfdf')) # true 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -