我正在使用这个APIhttps://developer-eu.elavon.com/docs/opayo/spec/api-reference-0#operation/createCi.
在这个环节中,他们说
cardholderName
required
string <= 45 characters
The name of the card holder
cardNumber
required
string <= 16 characters
The number of the card
expiryDate
required
string 4 characters
The expiry date of the card in MMYY format
securityCode
required
string [ 3 .. 4 ] characters
The card security code, also known as CV2, CVV, or CVC. This is used in CV2 checks.
我添加了字符串长度验证作为
[Required]
[StringLength(45)]
public string CardholderName { get; set; }
在这个API中,他们验证securityCode
是POST请求所需的字符串[3..4]字符。
如何为添加验证securityCode required string [ 3 .. 4 ] characters
?
我建议使用正则表达式,例如
[RegularExpression("^(0[1-9])|(1[0-2])2[1-9]$")]
public string ExpireDate {get; set;}
在这里,我们接受01..12
范围内的任何月份,也接受21..29
范围内的任意年份。安全代码相同:
[RegularExpression("^[0-9]{3,4}$")]
public string SecurityCode {get; set;}
这里我们接受3
或4
数字