Django regex validator message has no effect

后端 未结 4 1001
不思量自难忘°
不思量自难忘° 2020-12-31 04:48

I am trying to get it so that the validator tells you \"username must be alphanumeric\". This is my code so far. I have confirmed that it validates at the correct time. The

4条回答
  •  时光取名叫无心
    2020-12-31 05:01

    How about adding the error code:

    user = CharField(
        max_length=30,
        required=True,
        validators=[
            RegexValidator(
                regex='^[a-zA-Z0-9]*$',
                message='Username must be Alphanumeric',
                code='invalid_username'
            ),
        ]
    )
    

提交回复
热议问题