get Verify Code From Sms which is six digits by regular expression - Android java.util.regex

Android examples for java.util.regex:Digit Pattern

Description

get Verify Code From Sms which is six digits by regular expression

Demo Code

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

public class Main{

    public static String getVerifyCodeFromSms(String smsBody) {
        Pattern pattern = Pattern.compile("\\d{6}");
        Matcher matcher = pattern.matcher(smsBody);
        if (matcher.find()) {
            return matcher.group();
        }//from   ww  w.ja v  a2 s. c o  m
        return null;
    }

}

Related Tutorials