How to validate aadhaar card number in C++

In this tutorial, we will learn how to validate aadhaar card number in C++. Before directly moving to the topic i.e., how to validate aadhaar card number in C++. First, let us understand what is an aadhaar card number.

The aadhaar card number is a twelve(12) digit unique number. It has been governing by the Indian government. Therefore, this number is unique for every citizen of India.

Now, let us understand how to validate the aadhaar number. The aadhaar card number length is 12 digits. The aadhaar number is unique and does not start with 0 or 1. We validate through visiting the UIDIA website. Then entering the aadhaar card number. Then enter the OTP which is sent to the registered mobile number. By entering that OTP will validate the aadhaar card number. If it is the same as saved in the government database.

Let’s understand it with a program.

//illustrating how to validate 
// aadhaar card number
#include<iostream>
using namespace std;

int main()
{
    string s;
    int c;
    
    cout<<"enter your aadhaar card number";
    //enter aadhaar number
    cin>>s;
    //checking is it 12digit or not
    if(s.length()!=12)
    {
        cout<<"invalid aadhaar card number";
        exit(0);
    }
    
    else
    {
        // the first letter should not start with o or 1
        if(s[0]=='0' || s[0]=='1')
        {
        cout<<"invalid aadhaar card number";
        exit(0);
        }
        
    else
    {
        for(int i=0;i<12;i++)
        {
            if(isdigit(s[i])) // checks if value is number or not
            {
                c=c+1;
            }
        }
    }
        
    }

    if(c==12)
    cout<<"valid aadhaar number";
    
    else
    cout<<"invalid aadhaar number";
    
  return 0;
}

The above only check 2 things first whether aadhaar number is of 12 digits. Second, it should not start with 0 or 1. The above code displays the output as given below:

1. enter your aadhaar card number: 249844450851
   valid aadhaar number

2. enter your aadhaar card number: 63456653879
   invalid aadhaar number

3. enter your aadhaar card number: 058749538792
   invalid aadhaar number

4. enter your aadhaar card number: 182276482642
   invalid aadhaar number

 

Also, read:

Program to validate Email-Id using regex in C++

How to Validate a phone number with C++?

Leave a Reply

Your email address will not be published. Required fields are marked *