Java Validation Form tool class, the most complete in history

Source: Internet
Author: User
Tags rar

Package com.wiker.utils;
Import java.util.regex.*;
/**
*
* @version 1.0
* @author Wiker
* @since JDK 1.6
**/
public class Validateutils {
/** integer */
private static final String v_integer= "^-?" [1-9]\\d*$];

/** Positive integer */
private static final String v_z_index= "^[1-9]\\d*$";

/** Negative integer */
private static final String v_negative_integer= "^-[1-9]\\d*$";

/** Number */
private static final String v_number= "^ ([+-]?) \\d*\\.? \\d+$ ";

/** Positive */
private static final String v_positive_number= "^[1-9]\\d*|0$";

/** Negative */
private static final String v_negatine_number= "^-[1-9]\\d*|0$";

/** floating point number */
private static final String v_float= "^ ([+-]?) \\d*\\.\\d+$ ";

/** positive floating-point number */
private static final String v_posttive_float= "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$";

/** negative floating-point number */
private static final String v_negative_float= "^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*) $";

/** non-negative floating point number (positive floating point + 0) */
private static final String v_unpositive_float= "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?". 0+|0$ ";

/** non-positive floating-point number (negative floating-point number + 0) */
private static final String v_un_negative_float= "^ (-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)) | 0+|0$ ";

/** Mail * *
private static final String v_email= "^\\w+ ((-\\w+) | ( \\.\\w+)) *\\@[a-za-z0-9]+ ((\\.| -) [a-za-z0-9]+] *\\. [a-za-z0-9]+$];

/** Color */
private static final String v_color= "^[a-fa-f0-9]{6}$";

/** URL */
private static final String v_url= "^http[s]?:\ \/\\/([\\w-]+\\.) +[\\w-]+ ([\\w-./?%&=]*)? $ ";

/** Chinese Only * *
private static final String v_chinese= "^[\\u4e00-\\u9fa5\\uf900-\\ufa2d]+$";

/** only acsii characters */
private static final String v_ascii= "^[\\x00-\\xff]+$";

/** Postcode */
private static final String v_zipcode= "^\\d{6}$";

/** Mobile Phone * *
private static final String v_mobile= "^ (1) [0-9]{10}$";

/** IP Address */
private static final String v_ip4= "^ (25[0-5]|2[0-4]\\d|[ 0-1]\\d{2}| [1-9]?\\d] \ \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d] \ \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d] \ \. (25[0-5]|2[0-4]\\d| [0-1]\\d{2}| [1-9]?\\d) $ ";

/** Non-empty */
private static final String v_notempty= "^\\s+$";

/** Pictures * *
private static final String v_picture= "(. *) \ \. (JPG|BMP|GIF|ICO|PCX|JPEG|TIF|PNG|RAW|TGA) $ ";

/** Compressed Files */
private static final String v_rar= "(. *) \ \. (rar|zip|7zip|tgz) $ ";

/** Date */
private static final String v_date= "^ ((((1[6-9]|[ 2-9]\\d) \\d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\\d|3[01]) | (((1[6-9]| [2-9]\\d) \\d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\\d|30)] | (((1[6-9]| [2-9]\\d] \\d{2}) -0?2-(0?[ 1-9]|1\\D|2[0-8]) | (((1[6-9]| [2-9]\\d] (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) ( -0?2-29-)) (20|21|22|23|[ 0-1]?\\d): [0-5]?\\d:[0-5]?\\d$];

/** QQ Number */
private static final String v_qq_number= "^[1-9]*[1-9][0-9]*$";

function of/** telephone number (including verifying domestic area code, international area code, extension number) */
private static final String v_tel= "^ (([0\\+]\\d{2,3}-)? ( 0\\d{2,3})? (\\d{7,8}) (-(\\d{3,}))? $ ";

/** is used for user registration. Matches a string consisting of a number, 26 letters, or underscores */
private static final String v_username= "^\\w+$";

/** Letter */
private static final String v_letter= "^[a-za-z]+$";

/** Capital Letter */
private static final String v_letter_u= "^[a-z]+$";

/** Small Letter */
private static final String v_letter_i= "^[a-z]+$";

/** ID Card * *
private static final String V_idcard = "^ (\\d{15}$|^\\d{18}$|^\\d{17} (\\d| X|X)) $ ";

/** Authentication password (both digital and English exist) */
private static final String v_password_reg= "[a-za-z]+[0-9]";

/** Verify Password Length (6-18-bit) */
private static final String v_password_length= "^\\d{6,18}$";

/** Verifying two digits */
private static final String v_two_point= "^[0-9]+ (. [ 0-9]{2})? $ ";

/** verification one months of 31 days */
private static final String v_31days= "^ (0?[ 1-9]) | ((1|2) [0-9]) |30|31) $ ";


Private Validateutils () {}


/**
* Verify that it is not an integer
* @param value the string to validate for the string to validate
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Integer (String value) {
Return match (V_integer,value);
}

/**
* Verify that it is not a positive integer
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Z_index (String value) {
Return match (V_z_index,value);
}

/**
* Verify that it is not a negative integer
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Negative_integer (String value) {
Return match (V_negative_integer,value);
}

/**
* Verify that numbers are not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean number (String value) {
Return match (V_number,value);
}

/**
* Validation is not a positive number
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Positivenumber (String value) {
Return match (V_positive_number,value);
}

/**
* Verify that negative numbers are not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Negatinenumber (String value) {
Return match (V_negatine_number,value);
}

/**
* Verify one months of 31 days
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean is31days (String value) {
Return match (V_31days,value);
}

/**
* Verify that ASCII is not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean ASCII (String value) {
Return match (V_ascii,value);
}


/**
* Verification is not Chinese
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Chinese (String value) {
Return match (V_chinese,value);
}



/**
* Verify that it is not a color
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Color (String value) {
Return match (V_color,value);
}



/**
* Verify that the date is not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Date (String value) {
Return match (V_date,value);
}

/**
* Verify that the email address is not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean e-mail (String value) {
Return match (V_email,value);
}

/**
* Verify that it is not a floating point
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Float (String value) {
Return match (V_float,value);
}

/**
* Verify that it is not the correct ID number
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Idcard (String value) {
Return match (V_idcard,value);
}

/**
* Verify that the IP address is not correct
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean IP4 (String value) {
Return match (V_ip4,value);
}

/**
* Verify that the letter is not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean letter (String value) {
Return match (V_letter,value);
}

/**
* Verify that it is not a lowercase letter
* @param value to validate the string
* @return If it is a string conforming to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Letter_i (String value) {
Return match (V_letter_i,value);
}


/**
* Verify that it is not uppercase
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Letter_u (String value) {
Return match (V_letter_u,value);
}


/**
* Verify that the phone number is not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Mobile (String value) {
Return match (V_mobile,value);
}

/**
* Verify that negative floating-point numbers are not
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean negative_float (String value) {
Return match (V_negative_float,value);
}

/**
* Verify non-null
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Notempty (String value) {
Return match (V_notempty,value);
}

/**
* Verify the length of the password (6~18 bit)
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean number_length (String value) {
Return match (V_password_length,value);
}

/**
* Verify password (both digital and English exist)
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Password_reg (String value) {
Return match (V_password_reg,value);
}

/**
* Verify Picture
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean picture (String value) {
Return match (V_picture,value);
}

/**
* Verify the positive floating point number
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean posttive_float (String value) {
Return match (V_posttive_float,value);
}

/**
* Verify QQ number
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Qqnumber (String value) {
Return match (V_qq_number,value);
}

/**
* Verify Compressed files
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Rar (String value) {
Return match (V_rar,value);
}

/**
* Verify the phone
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Tel (String value) {
Return match (V_tel,value);
}

/**
* Verify two decimal places
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Two_point (String value) {
Return match (V_two_point,value);
}

/**
* Verify non-positive floating-point numbers
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean un_negative_float (String value) {
Return match (V_un_negative_float,value);
}

/**
* Verify non-negative floating point numbers
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean unpositive_float (String value) {
Return match (V_unpositive_float,value);
}

/**
* Verify URL
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean URL (String value) {
Return match (V_url,value);
}

/**
* Verify user registration. Matches a string consisting of a number, 26 letters, or underscores
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean UserName (String value) {
Return match (V_username,value);
}

/**
* Verification ZIP Code
* @param value to validate the string
* @return If it is a string that conforms to the format, return <b>true </b> otherwise <b>false </b>
*/
public static Boolean Zipcode (String value) {
Return match (V_zipcode,value);
}

/**
* @param regex Regular Expression string
* @param str to match the string
* @return returns True if STR conforms to regex format, otherwise false is returned;
*/
Private static Boolean match (string regex, String str)
{
Pattern pattern = pattern.compile (regex);
Matcher Matcher = Pattern.matcher (str);
return matcher.matches ();
}
}

Java Validation Form tool class, the most complete in history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.