create Alpha Numeric Input Filter - Android android.text

Android examples for android.text:InputFilter

Description

create Alpha Numeric Input Filter

Demo Code


//package com.java2s;

import android.text.InputFilter;
import android.text.Spanned;

public class Main {

    public static InputFilter[] createAlphaNumericInputFilter() {
        InputFilter inputFilter = new InputFilter() {
            @Override//from www . j a  v a 2s .  c o m
            public CharSequence filter(CharSequence source, //
                    int start, int end, Spanned dest, int dstart, int dend) {
                if (source.toString().matches("^[0-9a-zA-Z]+$")) {
                    return source;
                } else {
                    return "";
                }
            }
        };
        return new InputFilter[] { inputFilter };
    }
}

Related Tutorials