Saturday, August 31, 2013

Re: Form validation number and text only no space mac 4 numbers

Because the indentation is not correct, and doesn't correspond to what I sent you.

`return True` should be 4 chars left of where it currently is.


On Sat, Aug 31, 2013 at 7:23 PM, Gerd Koetje <deonlinefotograaf@gmail.com> wrote:
it somehow keeps returning True on everything

accepted = string.letters + string.digits
max_numbers = 4


def test(word):
    numbers = 0
    for c in word:
        if c.isdigit():
            numbers += 1
        if not c in accepted or numbers > max_numbers:
           return False
        return True

# profielnaam
class ProfielenForm(forms.ModelForm):


    def clean_profielnaam(self):

        logger.debug('>>>>>>>>>>>FORMS<<<<<<<<< %s', accepted)


        data = self.cleaned_data['profielnaam']
        testdata = test(data)
        logger.debug('>>>>>>>>>>>FORMS<<<<<<<<<< >>>>>DATA<<<<< %s', testdata)

        if testdata is "False":
            raise forms.ValidationError("Je mag alleen tekst en cijfers gebruiken en geen spaties")

        return data

    class Meta:
        model = Profielen
        fields = ('profielnaam',)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment