Is string only having digit and letter by regular expression - Android java.util.regex

Android examples for java.util.regex:Digit Pattern

Description

Is string only having digit and letter by regular expression

Demo Code

import android.text.TextUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean filter(String str) {
        String newStr = trim(str);
        String regEx = "[0-9A-Za-z_]*";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(newStr);
        if (m.matches()) {
            return true;
        }/*from   w  w w .ja  v  a  2 s  . com*/
        return false;
    }

}

Related Tutorials