Saudi Iqama/National Identity number field validation - textfield

Can someone help me with the criteria for field validation for Saudi iqama/National Identification number?
I know for Nationals it should start with 1 and for expats, it should start with 2 and the length should be 10.Anything else. This is for an application which has already seen some bad incoming data creating bugs, so don't want to take chances. Thanks in advance.

For (Id Type=’National Id’)  length = 10 , Id Number must start with ‘1’ in position 1. Multiply every number in an Odd Position (characters in positions 1,3,5..9) by 2. If the multiplication yields a 2 digit number then summate these 2 digits to yield a single digit. Summate the first 9 Characters for the ID number (post multiplication) to yield a 2 digit number (XY). If 10th digit of the ID number equals to “Zero”, then subtract 10 by the digit in position 2 (Y) in the summation total of the first 9 characters to yield a 2 digits (ZN), (N) should be equal to the 10th digit of the ID Number. Else, the 10th digit of the ID Number should be equal to 10 subtracted by the digit in position 2 (Y) in the Summation total of the first 9 Characters.

Saudi ID Number – 1058529940
Position 1 2 3 4 5 6 7 8 9 10
ID Nbr 1 0 5 8 5 2 9 9 4 0
Multiply 2 0 1 8 1 2 9 9 8
Summate 40
Validation Position 10 (value 0) = 10 – Digit 2
of Summation Total (0) = subtraction’s digit 2
e.g. ID Number = 1001244019
Position 1 2 3 4 5 6 7 8 9 10
ID Nbr 1 0 0 1 2 4 4 0 1 9
Multiply 2 0 0 1 4 4 8 0 2
Summate 21
Validation Position 10 (value 9) = 10 – Digit 2
of Summation Total (1)

Try validating using regex. ^[1|2]{1}[0-9]{9}$ this worked for me.
or if you are looking for a code that checks whether the id is correct or incorrect check this GitHub repo: https://github.com/alhazmy13/Saudi-ID-Validator. It's written in different programming languages, an it checks both National ID and Residence ID

Related

Does binary search in any case work with physical numbers themselves? Excluding 0

If there is a list in numerical order, (1 - 10) will binary search work with it? If the answer is no, can I have an explanation why it won't?
Binary search works with any array that is sorted.
Take searching for 3 as an example; assume we have a list of numbers from 1 to 10.
1 2 3 4 5 6 7 8 9 10
First, we divide it in two.
1 2 3 4 5 6 7 8 9 10
Since 3 is less than 6, we go with the first half.
1 2 3 4 5
Since 3 is less than 4, we go with the first half again.
1 2 3
Since 3 is equal to 3, we go with the second half.
And we have found 3.

External tool coding required for Parasoft

I know this is not as per guidelines, but i do need some help in parasoft extendaion tool coding part. I have all the logic that is required but dont know how to start
1 . I have 8 digit "50000002"
2 . I have another 8 digit checksum code "12121212"
3 . Now multiply each number with the 8 digit checksum code
5 0 0 0 0 0 0 2
1 2 1 2 1 2 1 2
==================
(5*1)(0*2)(0*1).....(2*2)
==================
4 . Now take the multiples and check if it is greater than equal or less than 9. if the multiples is less than 9, the value should be the number of multiple
For e.g. Last digit was 2*2 = 4 and 4 > 9 is false : so value would be 4
If it is greater then it that number should be subtracted by 9
For e.g. 9*2 = 18 and 18 > 9 is true : so the value would be 18-9 = 9
5 . Then we need to add all the number got from step 4 and use the below formuale
10-MOD(SUM(Step4_value),10)
if the value from the above formula is equal to 10 then it should give number 0 or else the value will the same of the formula.
EDITED

how to calculate the specific accumulated amount in t-sql

For each row, I need to calculate the integer part from dividing by 4. For each subsequent row, we add the remainder of the division by 4 previous and current lines and look at the whole part and the remainders from dividing by 4. Consider the example below:
id val
1 22
2 1
3 1
4 2
5 1
6 6
7 1
After dividing by 4, we look at the whole part and the remainders. For each id we add up the accumulated points until they are divided by 4:
id val wh1 rem1 wh2 rem2 RESULT(wh1+wh2)
1 22 5 2 0 2 5
2 1 0 1 (3/4=0) 3%4=3 0
3 1 0 1 (4/4=1) 4%4=0 1
4 2 0 2 (2/4=0) 2%4=2 0
5 1 0 1 (3/4=0) 3%4=3 0
6 7 1 2 (5/4=1) 5%4=1 2
7 1 0 1 (2/4=0) 2%4=1 0
How can I get the next RESULT column with sql?
Data of project:
http://sqlfiddle.com/#!18/9e18f/2
The whole part from the division into 4 is easy, the problem is to calculate the accumulated remains for each id, and to calculate which of them will also be divided into 4

Create new ID based on cumulative sum in excel vba

I need to create a new transport ID based on the cumulative sum of the volume being transported. Let´s say that originally everything was transported in truck A with a capacity of 25. Now I want to assign these items to shipments with truck B (Capacity 15).
The only real constraint is amt shipped cannot exceed capacity.
I can´t post a picture because of the restrictions...but the overall set up would be like this:
Old Trans # Volume New Trans # Cumulative Volume for Trans
1 1
1 9
1 3
1 7
1 4
2 9
2 10
3 8
3 5
3 9
4 4
4 6
4 8
5 9
5 1
5 5
5 8
6 3
6 4
6 3
6 4
6 4
6 7
7 7
7 10
7 4
8 10
8 6
8 7
9 4
9 9
9 6
10 7
10 4
10 1
10 1
10 5
10 2
11 9
11 3
11 9
12 8
12 5
12 9
13 9
Expected output would be that the first three entries would result in a new shipment ID of 1;the next two entries would result in a new shipment ID of 2;and so on... I´ve tried everthing that I know(excluding VBA): Index/lookup/if functions. My VBA skills are very limited though.Any tips?? thanks!
I think I see what you're trying to do here, and just using an IF formula (and inserting a new column to keep track):
In the Columns C and D, insert these formulas in row 3 and copy down (changing 15 for whatever you want your new volume capacity to be):
Column C: =IF(B3+C2<15,B3+C2,B3)
Column D: =IF(B3+C2<15,D2,D2+1)
And for the cells C2 and D2:
C2: = B2
D2: = A2
Is this what you're looking to do?
A simple formula could be written that 'floats' the range totals for each successive load ID.
In the following, I've typed 25 and 15 in D1:E1 and used a custom number format of I\D 0. In this way, the column is identified and the cell can be referenced as a true number load limit. You can hard-code the limits into the formula if you prefer by overwriting D$1 but you will not have a one-size-fits-all formula that can be copied right for alternate load limits as I have in my example..
      
The formula in D2 is,
=IF(ROW()=2, 1, (SUM(INDEX($B:$B, MATCH(D1, D1:D$1, 0)):$B2)>D$1)+ D1)
Fill right to E2 then down as necessary.

Using temporary extended table to make a sum

From a given table I want to be able to sum values having the same number (should be easy, right?)
Problem: A given value can be assigned from 2 to n consecutive numbers.
For some reasons this information is stored in a single row describing the value, the starting number and the ending number as below.
TABLE A
id | starting_number | ending_number | value
----+-----------------+---------------+-------
1 2 5 8
2 0 3 5
3 4 6 6
4 7 8 10
For instance the first row means:
value '8' is assigned to numbers: 2, 3 and 4 (5 is excluded)
So, I would like the following intermediairy result table
TABLE B
id | number | value
----+--------+-------
1 2 8
1 3 8
1 4 8
2 0 5
2 1 5
2 2 5
3 4 6
3 5 6
4 7 10
So I can sum 'value' for elements having identical 'number'
SELECT number, sum(value)
FROM B
GROUP BY number
TABLE C
number | sum(value)
--------+------------
2 13
3 8
4 14
0 5
1 5
5 6
7 10
I don't know how to do this and didn't find any answer on the web (maybe not looking with appropriate key words...)
Any idea?
You can do what you want with generate_series(). So, TableB is basically:
select id, generate_series(starting_number, ending_number - 1, 1) as n, value
from tableA;
Your aggregation is then:
select n, sum(value)
from (select id, generate_series(starting_number, ending_number - 1, 1) as n, value
from tableA
) a
group by n;