File tree Expand file tree Collapse file tree 3 files changed +84
-1
lines changed Expand file tree Collapse file tree 3 files changed +84
-1
lines changed Original file line number Diff line number Diff line change 1
1
from stdnum .ae import trn as vat # noqa: F401
2
2
from stdnum .ae import trn as business_tin # noqa: F401
3
- from stdnum .ae import trn as personal_tin # noqa: F401
3
+ from stdnum .ae import eid as personal_tin # noqa: F401
Original file line number Diff line number Diff line change
1
+ # eid.py - functions for handling UAE Emirates ID numbers
2
+ # ref:
3
+ # https://www.icp.gov.ae/en/
4
+
5
+ """Emirates ID (Emirates Identity Card Number)
6
+
7
+ The Emirates ID is a 15 digit number.
8
+
9
+ >>> validate('123456789012345')
10
+ '123456789012345'
11
+ >>> validate('1234-5678901-2345')
12
+ '123456789012345'
13
+ >>> validate('1234567890123456')
14
+ Traceback (most recent call last):
15
+ ...
16
+ stdnum.exceptions.InvalidLength: The number has an invalid length.
17
+ >>> validate(None)
18
+ Traceback (most recent call last):
19
+ ...
20
+ stdnum.exceptions.InvalidFormat: The number has an invalid format.
21
+ """
22
+
23
+ import re
24
+
25
+ from stdnum .exceptions import *
26
+ from stdnum .util import clean
27
+
28
+
29
+ _eid_re = re .compile (r'^\d{15}$' )
30
+
31
+
32
+ def compact (number ):
33
+ """Convert the number to the minimal representation. This strips the
34
+ number of any valid separators and removes surrounding whitespace."""
35
+ return clean (number , ' -' ).strip ()
36
+
37
+
38
+ def validate (number ):
39
+ """Check if the number is a valid Emirates ID. This checks the length and format."""
40
+ number = compact (number )
41
+ if len (number ) != 15 :
42
+ raise InvalidLength ()
43
+ if not _eid_re .match (number ):
44
+ raise InvalidFormat ()
45
+ return number
46
+
47
+
48
+ def is_valid (number ):
49
+ """Check if the number is a valid Emirates ID."""
50
+ try :
51
+ return bool (validate (number ))
52
+ except ValidationError :
53
+ return False
Original file line number Diff line number Diff line change
1
+ >>> from stdnum.ae import eid
2
+
3
+ >>> eid.validate('123456789012345')
4
+ '123456789012345'
5
+ >>> eid.is_valid('123456789012345')
6
+ True
7
+ >>> eid.validate('1234-5678901-2345')
8
+ '123456789012345'
9
+ >>> eid.is_valid('1234-5678901-2345')
10
+ True
11
+ >>> eid.validate(' 1234-5678901-2345 ')
12
+ '123456789012345'
13
+ >>> eid.is_valid(' 1234-5678901-2345 ')
14
+ True
15
+ >>> eid.validate(' 1234-5678901-2 345 ')
16
+ '123456789012345'
17
+ >>> eid.is_valid(' 1234-5678901-2 345 ')
18
+ True
19
+ >>> eid.validate('1234567890123456')
20
+ Traceback (most recent call last):
21
+ ...
22
+ stdnum.exceptions.InvalidLength: The number has an invalid length.
23
+ >>> eid.is_valid('1234567890123456')
24
+ False
25
+ >>> eid.validate('12345678901234A')
26
+ Traceback (most recent call last):
27
+ ...
28
+ stdnum.exceptions.InvalidFormat: The number has an invalid format.
29
+ >>> eid.is_valid('1234-567890123456')
30
+ False
You can’t perform that action at this time.
0 commit comments