is char Alpha Numeric String - Android java.lang

Android examples for java.lang:Character

Description

is char Alpha Numeric String

Demo Code


//package com.java2s;

public class Main {
    public static boolean isAlphaNumericString(String s) {
        boolean b = true;
        for (int i = 0; i < s.length(); i++) {
            if (!isAlphaNumeric(s.charAt(i))) {
                b = false;/* w ww  .  jav a 2s.  c om*/
                break;
            }
        }
        return b;
    }

    public static boolean isAlphaNumeric(char c) {
        return isAlpha(c) || isNumeric(c);
    }

    public static boolean isAlpha(char c) {
        return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
    }

    public static boolean isNumeric(char c) {
        return (c >= '0' && c <= '9');
    }
}

Related Tutorials