PHP verifies whether the credit card number is correct. PHP verification of credit card number is correct function this article mainly introduces PHP verification of credit card number is correct function, this article directly gives the implementation code, for more information about how to use PHP to verify whether the credit card number is correct
This article mainly introduces PHP functions used to verify whether a credit card number is correct. This article provides the implementation code directly. For more information, see
You can use the following PHP function to verify whether a card number is a credit card:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Function validateCard ($ cardnumber) { $ Cardnumber = preg_replace ("/\ D | \ s/", "", $ cardnumber); # strip any non-digits $ Cardlength = strlen ($ cardnumber ); If ($ cardlength! = 0) { $ Parity = $ cardlength % 2; $ Sum = 0; For ($ I = 0; $ I <$ cardlength; $ I ++) { $ Digit = $ cardnumber [$ I]; If ($ I % 2 = $ parity) $ digit = $ digit * 2; If ($ digit> 9) $ digit = $ digit-9; $ Sum = $ sum + $ digit; } $ Valid = ($ sum % 10 = 0 ); Return $ valid; } Return false; } |
Note <>: For more exciting tutorials, please pay attention to the help house programming
This article describes the PHP function used to verify whether a credit card number is correct. the implementation code is provided in this article...