Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validating the Aadhar card number in a application

we are developing a application which need to check whether user entering valid "AADHAR" number or not. i find some links and some "apis" but didn't meet final requirement please provide me a some useful material to solve this

What is Aadhaar?

Aadhaar is a 12 digit individual identification number issued by the Unique Identification Authority of India on behalf of the Government of India.

like image 634
Kiran Sunkari Avatar asked Dec 29 '14 09:12

Kiran Sunkari


People also ask

What is validation stage in aadhar?

This validation letter contains a secret code that is sent for validation after the Address Verifier consents to the use of his/her address by the requesting resident. After the request has been submitted, the resident will get the Aadhaar Validation Letter within 30 days from the date of the submitted request.

How can I know my Aadhar card status by application number?

Once the Aadhaar gets generated, you receive an SMS on the registered mobile number. You can also check status of Aadhaar by clicking on “Check Aadhaar Status” or https://resident.uidai.gov.in/check-aadhaar.


1 Answers

I think you are looking for Verhoeff algorithm, because UIDAI uses this algorithm for validating the aadhar number. You just need to create and use below class.

class VerhoeffAlgorithm{
        static int[][] d  = new int[][]
                {
                        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
                        {1, 2, 3, 4, 0, 6, 7, 8, 9, 5},
                        {2, 3, 4, 0, 1, 7, 8, 9, 5, 6},
                        {3, 4, 0, 1, 2, 8, 9, 5, 6, 7},
                        {4, 0, 1, 2, 3, 9, 5, 6, 7, 8},
                        {5, 9, 8, 7, 6, 0, 4, 3, 2, 1},
                        {6, 5, 9, 8, 7, 1, 0, 4, 3, 2},
                        {7, 6, 5, 9, 8, 2, 1, 0, 4, 3},
                        {8, 7, 6, 5, 9, 3, 2, 1, 0, 4},
                        {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
                };
        static int[][] p = new int[][]
                {
                        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
                        {1, 5, 7, 6, 2, 8, 3, 0, 9, 4},
                        {5, 8, 0, 3, 7, 9, 6, 1, 4, 2},
                        {8, 9, 1, 6, 0, 4, 3, 5, 2, 7},
                        {9, 4, 5, 3, 1, 2, 6, 8, 7, 0},
                        {4, 2, 8, 6, 5, 7, 3, 9, 0, 1},
                        {2, 7, 9, 3, 8, 0, 6, 4, 1, 5},
                        {7, 0, 4, 6, 9, 1, 3, 2, 5, 8}
                };
        static int[] inv = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};

        public static boolean validateVerhoeff(String num){
            int c = 0;
            int[] myArray = StringToReversedIntArray(num);
            for (int i = 0; i < myArray.length; i++){
                c = d[c][p[(i % 8)][myArray[i]]];
            }

            return (c == 0);
        }
        private static int[] StringToReversedIntArray(String num){
            int[] myArray = new int[num.length()];
            for(int i = 0; i < num.length(); i++){
                myArray[i] = Integer.parseInt(num.substring(i, i + 1));
            }
            myArray = Reverse(myArray);
            return myArray;
        }
        private static int[] Reverse(int[] myArray){
            int[] reversed = new int[myArray.length];
            for(int i = 0; i < myArray.length ; i++){
                reversed[i] = myArray[myArray.length - (i + 1)];
            }
            return reversed;
        }
    }

For More Info:-

  1. Verhoeff_Algorithm
  2. Google groups, Aadhar auth
  3. Actual aadhaaar is 11 digits long and not 12

EDIT:--

public static boolean validateAadharNumber(String aadharNumber){
        Pattern aadharPattern = Pattern.compile("\\d{12}");
        boolean isValidAadhar = aadharPattern.matcher(aadharNumber).matches();
        if(isValidAadhar){
            isValidAadhar = VerhoeffAlgorithm.validateVerhoeff(aadharNumber);
        }
        return isValidAadhar;
    }
like image 89
dReAmEr Avatar answered Sep 19 '22 18:09

dReAmEr