Welcome Guest, Not a member yet? Register   Sign In
Error when validating credit card with multiple parameters in valid_cc_number rule
#1

(This post was last modified: 06-03-2021, 03:38 PM by funcion.)

I am using the codeigniter valid_cc_number credit card validation rule following the documentation https://codeigniter.com/user_guide/libra...able-rules

It works when I add a card type: valid_cc_number[visa]

PHP Code:
$validation = \Config\Services::validation();
$validation->setRules(['card_number' => 'required|valid_cc_number[visa]']); 

If I specify more than one card type like this: valid_cc_number[visa,mastercard]

PHP Code:
$validation = \Config\Services::validation();
$validation->setRules(['card_number' => 'required|valid_cc_number[visa,mastercard]']); 

Quote:It shows me the following message: Validation.valid_cc_number

How can I validate the credit card number specifying more than one type of card as in the valid_cc_number rule?

Credit card types: amex, unionpay, carteblanche, dinersclub, discover, interpayment, jcb, maestro, dankort, mir, troy, mastercard, visa, uatp, verve, cibc, rbc, tdtrust, scotia, bmoabm, hsbc

Sample credit card numbers: https://www.paypalobjects.com/en_AU/vhel...umbers.htm

American Express: 378282246310005
Diners Club: 30569309025904
MasterCard: 5555555555554444
Visa: 4111111111111111
Reply
#2

Create custom validation library for validate cards

It s better
Go to app/validation. Php

See the libraries create one call in vlidation cong
Its the best way
Enlightenment  Is  Freedom
Reply
#3

(This post was last modified: 06-05-2021, 08:54 PM by InsiteFX. Edit Reason: Fixed quotes @includebeer )

Have the user select the card type then on form submit button add it to the rule set.

PHP Code:
$validation->setRules(['card_number' => "required|valid_cc_number[$cardType]"]); 

Then check your validation.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

@InsiteFX Great and simple solution! But change the single quotes to double quotes to get the value of $cardType...  Cool

PHP Code:
$validation->setRules(['card_number' => "required|valid_cc_number[$cardType]"]); 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

Hi! i have the same issue...but this solution is not good for user experience. How can I solve?
Reply
#6

This code is dangerous. Be sure to validate the value of $cardType before running the card_number validation.

PHP Code:
$validation->setRules(['card_number' => "required|valid_cc_number[$cardType]"]); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB