ó
ĝ˘TQc           @@ sÂ   d  Z  d d l m Z m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z e j d	  Z d Z d Z d d d d d g Z d e f d     YZ d S(   u!   
Hong Kong specific Form helpers
i    (   t   absolute_importt   unicode_literalsN(   t   EMPTY_VALUES(   t	   CharField(   t   ValidationError(   t
   smart_text(   t   ugettext_lazyu    ^(?:852-?)?(\d{4})[-\.]?(\d{4})$u   999u   992u   112u   2u   3u   5u   6u   8u   9u	   XXXX-XXXXu   852-XXXX-XXXXu   (+852) XXXX-XXXXu	   XXXX XXXXu   XXXXXXXXt   HKPhoneNumberFieldc           B@ st   e  Z d  Z i e d d j e   d 6e d d j e   d 6e d d j e   d 6Z d   Z	 d	   Z
 RS(
   uŞ  
    Validate Hong Kong phone number.
    The input format can be either one of the followings:
    'XXXX-XXXX', '852-XXXX-XXXX', '(+852) XXXX-XXXX',
    'XXXX XXXX', or 'XXXXXXXX'.
    The output format is 'XXXX-XXXX'.

    Note: The phone number shall not start with 999, 992, or 112.
          And, it should start with either 2, 3, 5, 6, 8, or 9.

    Ref - http://en.wikipedia.org/wiki/Telephone_numbers_in_Hong_Kong
    u=   Phone number should not start with one of the followings: %s.u   , u   disguiseu9   Phone number must be in one of the following formats: %s.u   invalidu9   Phone number should start with one of the followings: %s.u   prefixc         O@ s   t  t |   j | |   d  S(   N(   t   superR   t   __init__(   t   selft   argst   kwargs(    (    s<   ../Django//lib/python/django/contrib/localflavor/hk/forms.pyR	   /   s    c         @ s  t  t |   j      t k r& d St j d d t       t j    } | sl t	 |  j
 d   n  d | j d  | j d  f   x3 t D]+ }   j |  r t	 |  j
 d   q q Wt   f d   t  } t |  sŝ t	 |  j
 d	   n    S(
   Nu    u   (\(|\)|\s+|\+)u   invalidu   %s-%si   i   u   disguisec         @ s     j  |   S(   N(   t
   startswith(   t   prefix(   t   value(    s<   ../Django//lib/python/django/contrib/localflavor/hk/forms.pyt   <lambda>B   s    u   prefix(   R   R   t   cleanR   t   ret   subR   t   hk_phone_digits_ret   searchR   t   error_messagest   groupt   hk_special_numbersR   t   mapt   hk_phone_prefixest   any(   R
   R   t   mt   specialt   prefix_found(    (   R   s<   ../Django//lib/python/django/contrib/localflavor/hk/forms.pyR   2   s     "	(   t   __name__t
   __module__t   __doc__t   _t   joinR   t
   hk_formatsR   t   default_error_messagesR	   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hk/forms.pyR      s   	(   u   999u   992u   112(   u   2u   3u   5u   6u   8u   9(   R!   t
   __future__R    R   R   t   django.core.validatorsR   t   django.formsR   R   t   django.utils.encodingR   t   django.utils.translationR   R"   t   compileR   R   R   R$   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hk/forms.pyt   <module>   s   	