我使用以下正则表达式来验证使用javascript的信用卡号类型
@Entity
public class Emoji implements Serializable {
private static long serialVersionUID = 1L;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public static void setSerialVersionUID(long aSerialVersionUID) {
serialVersionUID = aSerialVersionUID;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
private Utilisateur createur;
private String titre;
@OneToMany(cascade = CascadeType.PERSIST)
private List<Message> conversations;
}
以前这段代码运行得很好但是现在它显示了上面的错误。任何人都可以查看并进行任何更改吗?
答案 0 :(得分:0)
更好的方法是使用LUHN测试。 https://en.wikipedia.org/wiki/Luhn_algorithm
/*
mod10( cardNumber )
parameters:
this function takes the text string card number and runs the Mod 10 formula on its respective digits.
description:
Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
returns:
this function returns true if the number passes the check digit test.
false otherwise.
*/
function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
var ar = new Array( cardNumber.length );
var i = 0,sum = 0;
for( i = 0; i < cardNumber.length; ++i ) {
ar[i] = parseInt(cardNumber.charAt(i));
}
for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
ar[i] *= 2; // every second digit starting with the right most (check digit)
if( ar[i] > 9 ) ar[i]-=9; // will be doubled, and summed with the skipped digits.
} // if the double digit is > 9, ADD those individual digits together
for( i = 0; i < ar.length; ++i ) {
sum += ar[i]; // if the sum is divisible by 10 mod10 succeeds
}
return (((sum%10)==0)?true:false);
}
答案 1 :(得分:0)
在http://www.regex101.com上输入它,它会告诉您此块中的问号:14})|?(6(
应该被删除,因为问号意味着前面的标记是可选的,但它前面是或者不是令牌的运算符。请注意,这与?:
不同,后者表示非捕获组。