Java String with only ASCII letter and digit

Description

Java String with only ASCII letter and digit


//package com.demo2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String s = "demo2s.com";
        int m = 2;
        int n = 2;
        System.out.println(allAlphaNum(s, m, n));
    }//from w  w w  .j av a 2  s .  c o  m

    public static boolean allAlphaNum(String s, int m, int n) {
        for (int i = m; i < n; i++)
            if (!isAlpha(s.charAt(i)) && !isDigit(s.charAt(i)))
                return false;
        return true;
    }

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

    public static boolean isDigit(int c) {
        return '0' <= c && c <= '9';
    }
}



PreviousNext

Related