1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
classRegisterSerializer(serializers.ModelSerializer): code = serializers.CharField(min_length=4, max_length=4, required=True, write_only=True) classMeta: model = models.User fields = ('mobile', 'password', 'code') extra_kwargs = { 'password': { 'min_length': 8, 'max_length': 16, 'write_only': True, } }
defvalidate_mobile(self, value): if not re.match(r'^1[3-9][0-9]{9}$', value): raise exceptions.ValidationError('mobile field error') return value
defvalidate(self, attrs):
|