需要有关使用正则表达式验证Addhar卡号的帮助。这是12位数字。以下格式。它可以包含0到9位数字。
EG。 0000 0000 0000
答案 0 :(得分:2)
试试这个正则表达式:
^\d{4}\s\d{4}\s\d{4}$
答案 1 :(得分:1)
我没有你的正则表达式,但可以使用此函数来检查有效的aadhar no。
function checkUID(uid) {
if (uid.length != 12) {
return false;
}
var Verhoeff = {
"d": [[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]],
"p": [[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]],
"j": [0, 4, 3, 2, 1, 5, 6, 7, 8, 9],
"check": function (str) {
var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[i % 8][parseInt(u, 10)]];
});
return c;
},
"get": function (str) {
var c = 0;
str.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = Verhoeff.d[c][Verhoeff.p[(i + 1) % 8][parseInt(u, 10)]];
});
return Verhoeff.j[c];
}
};
String.prototype.verhoeffCheck = (function () {
var d = [[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]];
var p = [[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]];
return function () {
var c = 0;
this.replace(/\D+/g, "").split("").reverse().join("").replace(/[\d]/g, function (u, i) {
c = d[c][p[i % 8][parseInt(u, 10)]];
});
return (c === 0);
};
})();
if (Verhoeff['check'](uid) === 0) {
return true;
} else {
return false;
}
}
当有效的aadhar为no时,此函数返回true,否则返回false。 例子
console.log(“”,checkUID(“111111111111”)); //假
答案 2 :(得分:1)
使用Verhoeff算法对Swift 4.0进行Aadhaar数验证
extension String {
subscript (i: Int) -> Character {
return self[self.index(self.startIndex, offsetBy: i)]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
}
}
// Convert a Character to an integer. So '3' becomes interceder 3.
extension Character {
var integerValue:Int {
return Int(String(self)) ?? 0
}
}
class VerhoeffAlgorithm {
// From https://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm
// based on the "C" implementation
// The multiplication table
let verhoeff_d : [[ 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],
];
// The permutation table
let verhoeff_p : [[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],
];
//Validates that an entered number is Verhoeff compliant. The check digit must be the last one.
func ValidateVerhoeff(num : String) -> Bool {
var c : Int = 0;
let ll : Int = num.count
for i in 0..<ll {
c = verhoeff_d[c][verhoeff_p[(i % 8)][(num[ll-i-1]).integerValue]]
}
return (c == 0);
}
}
答案 3 :(得分:0)
此正则表达式可帮助我完成基本验证:
[0-9]{12}
第一部分指定只需要0到9之间的数字。 第二部分指定您要在0到9之间输入12位数字。
答案 4 :(得分:0)
^(\ d {12} | \ d {16})$
尽可能长地输入类型
在Mvc模型中,例如:
[Required]
[RegularExpression(@"^(\d{12}|\d{16})$", ErrorMessage = "enter Integers only")]
[Display(Name = "Adar ID:")]
public long sid { get; set; }
答案 5 :(得分:0)
^[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}$
以上正则表达式支持以下格式
答案 6 :(得分:0)
/(^[0-9]{4}[0-9]{4}[0-9]{4}$)|(^[0-9]{4}\s[0-9]{4}\s[0-9]{4}$)|(^[0-9]{4}-[0-9]{4}-[0-9]{4}$)/
Aadhar 数字正则表达式验证
以下数字有效:
1111-2222-3333
或1111 2222 3333
或111122223333
以下无效:
11112222 3333
1111 22223333
1111-22223333
11112222-3333
1111 2222 3333
答案 7 :(得分:-1)
以上所有正则表达式都是错误的。 ^([0-9]){12} $是正确的。