Not really a Django question, just basic Python. For starters strip() will remove only leading and trailing chars in the set, not embedded chars.
Curiously though, with all due respect, this: if dataless.isdigit() != True: has beginner written all over it. What's wrong with: if not dataless.isdigit(): Comparing booleans by value is an interesting notion. But personally, Django is rooted on the principle of DRY (Don't Repeat Yourself) and if I wanted to store phone numbers I'd look to see who's done it already and lo and behold django-phonenumber-field <https://github.com/stefanfoulis/django-phonenumber-field>! https://github.com/stefanfoulis/django-phonenumber-field Try that maybe and save yourself a lot of thinking and hassle on the phone number formats. Regards, Bernd. On Friday, 16 March 2018 14:17:49 UTC+11, Carl Brubaker wrote: > > I'm trying to make my own phone number form, and I'm having trouble with > number validation. > > Since international numbers can use "(40) (30)" I want to check that only > numbers were entered. I can't seem to make it work though. > > def clean_international(self): > data = self.cleaned_data['international'] > # Take off () > dataless = data.strip('() ') > > if dataless.isdigit() != True: > raise ValidationError(_('Invalid number')) > > return data > > This always raises an error. Any suggestions? Thanks! > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d1b0df6e-bb8e-40ae-a8a8-876e16d84f5c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.