validation.py 667 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import re
  4. NAME_RE = re.compile(ur'^[\u4e00-\u9fa5a-zA-Z0-9·]{2,20}$')
  5. PASSWORD_RE = re.compile(r'[A-Za-z0-9@#$%^&+=]{6,}')
  6. PHONE_NUMBER_RE = re.compile(r'^(1\d[\d]{9}$)|((400|800)-?(\d{3})-?(\d{4}))|(0\d{9,10})$')
  7. CARD_NO_RE = re.compile(r"[A-z\d]{1,32}$")
  8. def check_phone_number(phone, allow_null = False):
  9. if allow_null and not phone:
  10. return True
  11. if not phone:
  12. return False
  13. return PHONE_NUMBER_RE.match(phone)
  14. def check_entity_name(name, allow_null = False):
  15. if not name and allow_null:
  16. return True
  17. if not name:
  18. return False
  19. return NAME_RE.match(name)