gpt4 book ai didi

java - 在应用程序中验证 Aadhar 卡号

转载 作者:搜寻专家 更新时间:2023-10-30 21:42:24 24 4
gpt4 key购买 nike

我们正在开发一个应用程序,它需要检查用户是否输入了有效的“AADHAR”号码。我找到了一些链接和一些“api”,但没有达到最终要求,请给我一些有用的 Material 来解决这个问题

What is Aadhaar?

Aadhaar 是印度唯一身份识别机构代表印度政府颁发的 12 位个人识别码。

最佳答案

我认为您正在寻找 Verhoeff 算法,因为 UIDAI 使用此算法来验证 aadhar 数。您只需要创建和使用下面的类。

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;
}
}

更多信息:-

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

编辑:--

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;
}

关于java - 在应用程序中验证 Aadhar 卡号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27686384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com