Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Methods + Expiration Date Year Length + Separator Style #16

Open
carmelogallo opened this issue Oct 1, 2015 · 0 comments
Open

Comments

@carmelogallo
Copy link

Hi guys, congratulation so far!

Validation Methods:
I just wanted to tell you to if you can add a method which return a boolean if the credit card number, expiration date and cvv is in a valid format. I created it subclassing your class but would be better if you can add it directly in your code ;) Here the code:

    func isValidCCNumber() -> Bool {

        let ccNumberRegex = "^(([0-9]{4})[-|\\s| ]([0-9]{4})[-|\\s| ]([0-9]{4})[-|\\s| ]([0-9]{4}))|(([0-9]{4})[-|\\s| ]([0-9]{6})[-|\\s| ]([0-9]{5}))"
        let ccNumberPredicate = NSPredicate(format:"SELF MATCHES %@", ccNumberRegex)
        return ccNumberPredicate.evaluateWithObject(self.text!)
    }

    func isValidCCEpirationDate() -> Bool {

        let ccExpirationDateRegex = "(?:0[1-9]|1[0-2])\\/2[0-9]{3}"
        let ccExpirationDatePredicate = NSPredicate(format:"SELF MATCHES %@", ccExpirationDateRegex)
        return ccExpirationDatePredicate.evaluateWithObject(self.text!)
    }

    func isValidCCCvv() -> Bool {

        let ccCvvRegex = "^([0-9]{3,4})$"
        let ccCvvPredicate = NSPredicate(format:"SELF MATCHES %@", ccCvvRegex)
        return ccCvvPredicate.evaluateWithObject(self.text!)
    }

Expiration Date Year Length:
In my app I need to use 4 digit number in the textfield but actually your code allow just 2. Would be better if you can let the user decide the length.

Separator Style:
In your app you automatically add the separation in the credit card number, which is an whitespace, and in the cvv, which is an " / ". Would be better if you can let the user decide them.

Hope you'll include them ;)

Cheers,
Carmelo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant