Java String Starts Wtih startsWithDigitsFollowedByLetters(String str)

Here you can find the source of startsWithDigitsFollowedByLetters(String str)

Description

Checks whether a string starts with digits and might contains after the digits only letters

License

EUPL

Parameter

Parameter Description
str the string to check

Return

true if the string starts with digits, and is followed by letters

Declaration

public static boolean startsWithDigitsFollowedByLetters(String str) 

Method Source Code

//package com.java2s;
/**/*from   ww  w  .j a v  a  2  s . co m*/
 * Copyright 2013 European Parliament
 *
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and limitations under the Licence.
 */

public class Main {
    /**
     * Checks whether a string starts with digits and might contains after the digits only letters
     *
     * @param str the string to check
     * @return true if the string starts with digits, and is followed by letters
     */
    public static boolean startsWithDigitsFollowedByLetters(String str) {
        int strLen = str.length();
        boolean startsWithDigits = false;

        int startForLetters = 0;
        for (int i = 0; i < strLen; i++) {
            if (Character.isDigit(str.charAt(i))) {
                startsWithDigits = true;
                continue;
            }
            startForLetters = i;
            break;
        }
        boolean followedByLetters = true;
        if (startsWithDigits && startForLetters > 0) {
            for (int i = startForLetters; i < strLen; i++) {
                if (!Character.isLetter(str.charAt(i))) {
                    followedByLetters = false;
                    break;
                }
            }
        }
        return startsWithDigits && followedByLetters;

    }
}

Related

  1. startsWithCharacter(String str, String matchChars)
  2. startsWithCommonPackagePrefix(String inputText)
  3. startsWithConcatenation(String string, String... prefixes)
  4. startsWithConcatenationOf(String testee, String firstPrefix, String secondPrefix)
  5. startsWithCS(String a, String b)
  6. startsWithHtml(Object object)
  7. startsWithIC(String s1, String... strings)
  8. startsWithIgnoreCase(final String base, final String start)
  9. startsWithIgnoreCase(final String haystack, final String needle)