android: the first digit in the edit text can not be zero

There is an alternative way in which you can use textWatcher .Check length of editable text inside afterTextChange method .if length is 1 and string is 0 than remove 0 .


Its just simple as that.

edContactNumber.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() == 1 && s.toString().startsWith("0")) {
                s.clear();
            }
        }
    });