[Fixed]-Python regex remove all non-numberic characters and ensure valid phone number

1๐Ÿ‘

โœ…

I dont think you can do that really โ€ฆ however you could probably specify the form input as only numeric (perhaps with forms.IntegerField)

or you could write your own validator

from django.core.exceptions import ValidationError

def validate_numeric(value):
    if not (9 <= len(re.sub("[^0-9]","",value)) <= 15):
        raise ValidationError('%s is not a valid phone number' % value)
๐Ÿ‘คJoran Beasley

Leave a comment