Java Number Range Create range(String field, int start, int end)

Here you can find the source of range(String field, int start, int end)

Description

Validate how long a field can be

License

Open Source License

Parameter

Parameter Description
field The field
start Range starts
end Range ends

Return

True if the field is within range

Declaration

public static boolean range(String field, int start, int end) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 - 2013 Ushahidi Inc.
 * All rights reserved/*from w w w .j  a va2 s. com*/
 * Website: http://www.ushahidi.com
 *
 * GNU AFFERO GENERAL PUBLIC LICENSE Version 3 Usage
 * This file may be used under the terms of the GNU AFFERO GENERAL
 * PUBLIC LICENSE Version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE included in the
 * packaging of this file. Please review the following information to
 * ensure the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 requirements
 * will be met: http://www.gnu.org/licenses/agpl.html.
 ******************************************************************************/

public class Main {
    /**
     * Validate how long a field can be
     *
     * @param field The field
     * @param start Range starts
     * @param end   Range ends
     * @return True if the field is within range
     */
    public static boolean range(String field, int start, int end) {
        if (field == null) {
            return false;
        }

        int length = field.length();

        if (end >= length) {
            end = length - 1;
        }

        return (start >= 0) && (end >= 0) && (start <= end) && (length > 0);
    }
}

Related

  1. range(int v, int min, int max)
  2. range(int value, int min, int max)
  3. range(Integer from, Integer to)
  4. range(long array[])
  5. range(long start, long end)
  6. range(String input[], int beginIndex, int endIndex)
  7. range(String second, String first)
  8. range(T val, T min, T max)
  9. RangeConvert(float start, float end, float newStart, float newEnd, float value)