23 Sept 2015

Pan Card Validation in Android EditText

Sample code for PAN card number validation.
PAN card number is a unique national number issued in India for tax related purposes.

 PAN structure is as follows: AAAAA9999A: First five characters are letters, next 4 numerals, last character letter.

To validate PAN card, call this line of code :-

mEdtPanNumber.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() == 10) {
                    String s = editable.toString(); // get your editext value here
                    Pattern pattern = Pattern.compile("[a-z]{5}[0-9]{4}[a-z]{1}");
                    Matcher matcher = pattern.matcher(s);
                    // Check if pattern matches
                    if (matcher.matches()) {
                    panNumber = editable.toString();
                } else {
                    Toast.makeText(DetailsActivity.this, getString(R.string.plz_enter_your_correct_pan_num), Toast.LENGTH_LONG).show();
                }
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                // TODO Auto-generated method stub
            }
        });

1 comment:

  1. hi i want to get specific letter from pan number for eg this is my pan number AKNPJ4611N in this i want AKN separate verificatiob than P as separate

    ReplyDelete