Example usage for android.text TextUtils isDigitsOnly

List of usage examples for android.text TextUtils isDigitsOnly

Introduction

In this page you can find the example usage for android.text TextUtils isDigitsOnly.

Prototype

public static boolean isDigitsOnly(CharSequence str) 

Source Link

Document

Returns whether the given CharSequence contains only digits.

Usage

From source file:Main.java

public static boolean checkRegParams(String nick, String password, String qq) {
    if (!TextUtils.isEmpty(nick) && !TextUtils.isEmpty(password) && !TextUtils.isEmpty(qq)
            && TextUtils.isDigitsOnly(qq)) {
        return true;
    } else {//from w w  w  . j a  v  a  2s. c  o m
        return false;
    }
}

From source file:Main.java

/**
 * Returns <tt>true</tt> if input String is not empty and Numeric.
 *
 * @param str// w  ww .j  a v  a2  s  . com
 * @return
 */
public static boolean isNumeric(String str) {
    return !TextUtils.isEmpty(str) && TextUtils.isDigitsOnly(str);
}

From source file:Main.java

public static boolean isValid(String expiry) {

    if (TextUtils.isEmpty(expiry)) {
        return false;
    }/*from   w  w  w . jav a 2s  . c o  m*/

    if (expiry.length() != LENGTH_EXPIRY_DATE) {
        return false;
    }

    // check all numeric
    if (!TextUtils.isDigitsOnly(expiry)) {
        return false;
    }

    // check month valid
    int month = Integer.parseInt(expiry.substring(0, 2));

    if (month < 1 || month > 12) {
        return false;
    }

    return true;
}

From source file:Main.java

public static boolean isValidCv2Number(String cv2) {
    if (TextUtils.isEmpty(cv2)) {
        return false;
    }/*from  ww w.j ava  2s . c  o  m*/

    if (cv2.length() < CV2_LENGTH_MIN || cv2.length() > CV2_LENGTH_MAX) {
        return false;
    }

    // check all numeric
    if (!TextUtils.isDigitsOnly(cv2)) {
        return false;
    }

    return true;
}

From source file:Main.java

public static boolean isValidCardNumber(String pan) {
    if (TextUtils.isEmpty(pan)) {
        return false;
    }//from w ww  .  j a v a 2 s.c  om

    if (pan.length() < PAN_LENGTH_MIN || pan.length() > PAN_LENGTH_MAX) {
        return false;
    }

    // check all numeric
    if (!TextUtils.isDigitsOnly(pan)) {
        return false;
    }

    return true;
}

From source file:Main.java

public static String formatDateTime(Context context, long time) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
    Date d = new Date(time);
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    int year = Integer.parseInt(TextUtils.isDigitsOnly(sdf.format(d)) ? sdf.format(d) : currentYear + "");
    if (currentYear == year) {
        return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE
                //| DateUtils.FORMAT_SHOW_WEEKDAY
                //| DateUtils.FORMAT_SHOW_YEAR
                | DateUtils.FORMAT_ABBREV_MONTH
                //| DateUtils.FORMAT_ABBREV_WEEKDAY
                | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME);
    } else {//from w  w  w  . ja  v  a2 s.c o  m
        return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE
                //| DateUtils.FORMAT_SHOW_WEEKDAY
                | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH
                //| DateUtils.FORMAT_ABBREV_WEEKDAY
                | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME);
    }

}

From source file:Main.java

private static String generateKeyNameForTaintInfo(Set<String> allIntentKeys) {
    String keyName = keyBaseName;
    int counter = 0;

    for (String intentKey : allIntentKeys) {
        if (intentKey.startsWith(keyBaseName)) {
            String possibleNumber = intentKey.substring(keyBaseName.length());
            if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                int currentCounter = Integer.parseInt(possibleNumber);
                counter = currentCounter + 1;
            }/* w w w  . ja va2  s  .co m*/
        }
    }

    if (counter != 0)
        keyName += counter;

    return keyName;
}

From source file:Main.java

public static String getTweetId(String in) {

    if (TextUtils.isEmpty(in)) {
        return null;
    }/*ww w  .  j av a  2  s .com*/

    if (in.indexOf("twitter") >= 0 || in.indexOf("t.co") >= 0) {

        Uri tweet = Uri.parse(in);

        String lastPath = tweet.getLastPathSegment();
        if (TextUtils.isEmpty(lastPath) == false && TextUtils.isDigitsOnly(lastPath)) {
            return lastPath;
        }
    }
    return null;
}

From source file:Main.java

public static String getSoundCloudStream(String baseUrl, String clientId) {
    //196567484/*from   w w  w . j a v a 2  s . co  m*/
    final Uri uri = Uri.parse(baseUrl);
    final List<String> segments = uri.getPathSegments();
    String id = null;
    for (int index = segments.size() - 1; index >= 0; index--) {

        if (TextUtils.isDigitsOnly(segments.get(index))) {
            id = segments.get(index);
            break;
        }
    }

    return getSoundCloudStreamFromTrackId(id, clientId);
}

From source file:Main.java

public static void registerNewSourceSinkConnection(int counter, Bundle bundle) {
    Log.i("PEP", "in registerNewSourceSinkConnection(int counter, Bundle bundle)");
    int taintInfoKeyCounter = 0;

    if (bundle != null) {
        for (String intentKey : bundle.keySet()) {
            if (intentKey.startsWith(keyBaseName)) {
                String possibleNumber = intentKey.substring(keyBaseName.length());
                if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                    int currentCounter = Integer.parseInt(possibleNumber);
                    if (taintInfoKeyCounter < currentCounter)
                        taintInfoKeyCounter = currentCounter;
                }//from  w w w.j  av  a 2 s  . com
            }
        }

        if (taintInfoKeyCounter == 0) {
            Log.i("PEP", "bundle:" + bundle.toString());
            if (bundle.containsKey(keyBaseName)) {
                String taintSourceCats = bundle.getString(keyBaseName);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        } else {
            if (bundle.containsKey(keyBaseName + taintInfoKeyCounter)) {
                String taintSourceCats = bundle.getString(keyBaseName + taintInfoKeyCounter);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        }
    }
}