正则表达式符合要求(000)000-0000,但未保存在后端?

时间:2018-06-20 06:59:39

标签: python regex django ember.js

常规表达式无法正常工作(不能存储在数据库中),但是它可以用于其他正则表达式,例如/.*/(存储在数据库中)

代码在ember js中,后端是Python Django。当我继续输入“ *”时,它被接受并保存了电话号码

if(value == 'phone'){
     if(this.get('user.phone').length>0){
      if (( /^\(\d{3}\)\s\d{3}-\d{4}$/.test(this.get('user.phone'))) ){
        const user_obj = {
            phone: this.get('user.phone'),
            sessionid: localStorage.getItem('session_id'),
        }
        set(this, 'pass_user', user_obj);
        this.set('invalidPhone', false);
      }
      else{
        this.set('invalidPhone', true);
      }     
    }
    else{
      this.set('invalidPhone', false);
    }
  }

这是用于保存数据的django代码

class SaveOfficeSpaceAPIView(APIView):

    def post(self, request, *args, **kwargs):
        session_id = request.POST.get('sessionid')
        own_obj = SearchWarehouse.objects.get(session_id=session_id)
        office_space = request.POST.get('officespace')
        loading_dock = request.POST.get('loadingdock')
        transportation_services = request.POST.get('transportation_services')
        warehouse_equipment = request.POST.get('warehouse_equipment')
        technology_services = request.POST.get('technology_services')
        name = request.POST.get('name')
        email = request.POST.get('email')
        phone = request.POST.get('phone')
        need = request.POST.get('need')

        if office_space:
            if office_space == 'Yes':
                own_obj.office_space = True
            else:
                own_obj.office_space = False

        if loading_dock:
            if loading_dock == 'Yes':
                own_obj.loading_dock = True
            else:
                own_obj.loading_dock = False

        if transportation_services:
            if own_obj.transportation_services == True:
                own_obj.transportation_services = False
            else:
                own_obj.transportation_services = True

        if warehouse_equipment:
            if own_obj.warehouse_equipment == True:
                own_obj.warehouse_equipment = False
            else:
                own_obj.warehouse_equipment = True

        if technology_services:
            if own_obj.technology_services == True:
                own_obj.technology_services = False
            else:
                own_obj.technology_services = True

        if name:
            own_obj.name = name
        elif email:
            own_obj.email = email
        elif phone:
            own_obj.phone_number = phone
        elif need:
            own_obj.needs = need

        own_obj.save()

        return HttpResponse(json.dumps({'status': 'success'}))

请指向正确的方向

0 个答案:

没有答案