我需要编辑文本的正则表达式验证,只有当edittext至少有一个字符和一个数字时才允许

时间:2017-09-27 15:12:09

标签: android

检查edittext是否包含字符和数字的组合

1 个答案:

答案 0 :(得分:0)

        editText.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) {
                editText.getText().toString().trim();
                // MATCH IT HERE WITH THAT REGEX
                // COMBINATION OF ONE LETTER AND ONE DIGIT ([a-zA-Z])(\d)
                // COMBINATION OF LETTERS AND DIGITS AFTER ([a-zA-Z]*)(\d*)
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });