Hello,
I have a script that is taking credit card payment and I'm validating user input in a php script. Things are working fine until I try to validate the CVV number. For American Express (AMEX) it should be 4 numerical digits. For MasterCard or Visa (everything else) it should be 3 numerical digits.
When I use the following regular expression, it correctly throws an error if the AMEX CVV is less than 4 digits. But if it is not AMEX (e.g. it is mastercard or visa) I only get an error if the input is 1 or 2 digits. It should only validate for 3 digits, but 4 digits also validates.
Can somebody tell me why this doesn't work?
trim($cvv);
If ($paymentmethod == "AMEX")
{
If (!ereg('([0-9]{4})', $cvv))
{
$errortext = "Please enter a valid CVV code";
exit;
}
}
// else mastercard or visa
elseif (!ereg('([0-9]{3})', $cvv))
{
$errortext = "Please enter a valid CVV code";
exit;
}