import re
class MobileViewSet(ViewSet):
@action(methods=['post'], detail=False)
def check(self, request, *args, **kwargs):
mobile = request.data.get('mobile', None)
if not mobile:
return APIResponse(1, 'mobile field required')
if not re.match(r'^1[3-9][0-9]{9}$', mobile):
return APIResponse(1, 'mobile field error')
try:
models.User.objects.get(mobile=mobile)
return APIResponse(msg=True) # 手机号存在
except:
return APIResponse(msg=False) # 手机号不存在