Here you can find the source of startsWithDigitsFollowedByLetters(String str)
Parameter | Description |
---|---|
str | the string to check |
public static boolean startsWithDigitsFollowedByLetters(String str)
//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; } }