Question : I am trying to validate a credit card number on a cfform

I am trying to produce a customer input page and I am trying to validate a credit card niumber. I put e.g. 3214-5435-3245-6574 or any other 16 digit num and it wont take it. I take spaces out, leave them in, no way does it accept it. What can I do. I have to use cfform and cfinput.




>  

                 
           
               
               
               
                 
                   
         
         
                   
         

                      Your Payment Details:
                       
Credit Card Type:
                 
                       
                        value = "Visa" checked >Visa Card
                         
                        value = "Discover" >Discover Card
                         
                        value = "Master" >MasterCard
                         

                   
* Credit Card  ##:                              size = "16"
                              required = "yes"
                              validate = "creditcard"
                     message = "Please enter a valid Card Number">    
                                       
             
* Expiration Date:                       
                         required ="yes"
                         validate = "date"
                         message = "Please enter a valid expiration date">
             

     


                                        value = "Review Order" onClick="fnCheck();">
     

Answer : I am trying to validate a credit card number on a cfform

Especiailly with something like credit card numbers you should also validate server side - not just in javascript.

Here is what I use :









      
            Variable#" = false>
      

      
            
            
            
            
                  
                        tNumber) EQ 13) OR (Len(ATTRIBUTES.AccountNumber) EQ 16))>
                              
                        
                              
                        

                  

                  
                        er) NEQ 16>
                              
                        
                              
                        

                  

                  
                        er) NEQ 15>
                              
                        
                              
                        

                  

                  
                        er) NEQ 16>
                              
                        
                              
                        

                  

                  
                        
                  

            

            
            
                  
                        checkSumTotal = 0;
                        digitSum = 0;
                        multiplier = 1;
                        for (digitCounter = #Len(ATTRIBUTES.AccountNumber)#; digitCounter GT 0; digitCounter = digitCounter - 1)
                        {
                              // get digit and double if necessary
                              digitSum = multiplier * Val(Mid(#ATTRIBUTES.AccountNumber#, digitCounter, 1));
                              // mathematic trick to get sum of the two digits if number is 10, 12, 14, 16, or 18
                              if (digitSum GT 9)
                              {
                                    digitSum = digitSum - 9;
                              }
                              // add current digit totals to checkSum Total
                              checkSumTotal = checkSumTotal + digitSum;
                              // set multiplier for next digit (i.e. mathematic trick to flip between 2 and 1)
                              multiplier = 3 - multiplier;
                        }
                        // mark the card as invalid if it did not pass the Luhn Mod-10 Test
                        if ((checkSumTotal mod 10) NEQ 0)
                        {
                              ValidCard = false;
                        }
                  

            

            Variable#" = ValidCard>
      

      
            
      




I removed the other account types we also allow (we have other account types besides Credit card numbers like Departmental Accounts, etc.  Account types are 3 digit numbers and we make sure that the account type for credit cards start with a 0.

For example:

Visa : 001
Mastercard : 002
American Express : 003
Discover: 004

Departmental Accounts : 200

Note this is not the account number - just the account type.

You could easily add other types to the above such as Corporate accounts, student accounts, etc. just by adding a new case to the switch....
Random Solutions  
 
programming4us programming4us