mercredi 17 août 2016

Check if part of text matches a regex

I'm trying to build a component similar to Google Play's credit card adding:

demo

Where the user starts typing the credit card number, and only the credit card images that stay visible, are of the cards that matches part of the credit card number pattern.

For example:

Looking at MasterCard regex: ^5[1-5][0-9]{14}$

If the user type "5", "53", "531", the image of master card should be visible.

I guess it can be done with Pattern and Matcher class, but how?

Using match() method is not good, as it trying to match against all the pattern.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire