developer:ios-checkexpdate

verifyExpDate : Verify the expiration date of a credit card

Description

This method takes in the credit card expiration date as a string. The date has a format of two digits for month and year. The month and year are not required to have a separator.

ie. 09/15
ie. 0915
ie. 09.15
ie. 09-15

It takes all the above form as a valid expiration date input.

The method will calculate the input date against the current date. It returns true if the expiration date is valid. Returns false if the expiration date is invalid.

Code Snippet

-(void)checkExpDate
{
    CreditCardPayment *ccPayment = [[CreditCardPayment alloc]init];
 
    NSString *expDate = @"09-15";
 
    if([ccPayment verifyExpDate:expDate])
    {
        NSLog(@"Expiration date is valid");
    }
 
    else
    {
        NSLog(@"Expiration date is invalid");
    }
}
developer/ios-checkexpdate.txt · Last modified: 2014/04/30 09:36 by jlei

Page Tools