Java random password generation and matching with mailbox, mobile phone number _java

Source: Internet
Author: User
Tags stringbuffer

Nonsense not to say, directly to everyone to paste the Java code, the code has commented, write a bad, but also please everyone a lot of attention.

The code looks like this:

Package com.alibaba.uyuni.common.util;
Import Java.util.Random; public class Generatepassword {/** * generate random password * @param pwd_len * Total length of password generated * @return password string/public static string Genrand Omnum (int pwd_len) {///26*2 Letter + 10 number final int maxnum = n; int i;//generated random number int count = 0;/////////////////////////////////////  ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', '
X ', ' y ', ' z ', ' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};
StringBuffer pwd = new StringBuffer ("");
Random r = new Random (); while (Count < Pwd_len) {//Generate random numbers, take absolute values to prevent negative numbers from being generated, I = Math.Abs (R.nextint (Maxnum));//Generate maximum number of 62-1 if (i >= 0 &&amp ;
I < str.length) {pwd.append (str[i]); count++;}
return pwd.tostring (); public static void Main (string[] args) {System.out.println (Genrandomnum (6));/}} Package com.alibaba.uyuni.coMmon.util;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; public class Regexutils {/** * Authentication email * @param email email address, format: zhangsan@zuidaima.com,zhangsan@xxx.com.cn,xxx representative Mail Service provider * Return validation successfully returns true, validation fails return false/public static Boolean Checkemail (String email) {String regex = ' \\w+@\\w+\\.[ a-z]+ (\\.[ 
a-z]+)? "; 
Return pattern.matches (regex, email); /** * Verify * * * * @param idcard Resident * * * Number 15 or 18 digits, the last one may be a number or letter * @return validation successfully returns TRUE, validation failure returns false */public static Boolean CH 
Eckidcard (String idcard) {string regex = ' [1-9]\\d{13,16}[a-za-z0-9]{1} '; 
Return pattern.matches (Regex,idcard); /** * Verify mobile phone number (support international format, +86135xxxx ...) (Mainland China), +00852137xxxx ... (Hong Kong, China) * @param Mobile Mobile, Unicom, telecom operator number segment *<p>: 134 (0-8), 135, 136, 137, 138, 139, 147 (expected for TD Internet Card) *, 150, 151, 152, 157 (TD-specific), 158, 159, 187 (not enabled), 188 (TD-specific) </p> *<p> Unicom segment: 130, 131, 132, 155, 156 (World Wind Dedicated), 185 (not enabled), 186 (3g) </ P> *<p> Telecom Number: 133, 153, 180 (not enabled), 189</p> * @return validation successfully returns true, validation fails return false/public static boolEan Checkmobile (String mobile) {string regex = "(\\+\\d+)? 1[3458]\\d{9}$"; 
Return pattern.matches (Regex,mobile); /** * Verify the fixed phone number * @param phone phone number, format: Country (region) telephone code + area code (city code) + telephone number, such as: +8602085588447 * <p><b> Country (region) code:< /b> the standard country (region) code for the country (region) that identifies the phone number. It contains one or more digits from 0 to 9, and the number is followed by a space-delimited country (region) code. </p> * <p><b> Area code (city codes):</b> this may contain one or more digits from 0 to 9, the region or city code is placed in parentheses--* the country (region) that does not use the region or city code, the component is omitted. </p> * <p><b> Phone number:</b> This contains one or more digits from 0 to 9 </p> * @return Validation successfully returns TRUE, validation failure returns false */public s Tatic Boolean Checkphone (String phone) {string regex = ' (\\+\\d+)? ( \\d{3,4}\\-?)? 
\\d{7,8}$ "; 
Return pattern.matches (regex, phone); /** * validating integers (positive and negative integers) * @param digit Integer * between one or more than 0-9 * @return validation returns true successfully, validation failure returns false */public static Boolean Checkdigit ( String digit) {string regex = ' \\-?[ 
1-9]\\d+ "; 
Return pattern.matches (Regex,digit); /** * verifies integers and floating-point numbers (positive and negative integers) * @param decimals a floating-point number between one or more digits, such as: 1.23,233.30 * @return Validation returns true successfully, validation fails back to FALSE/public static Boolean Checkdecimals (String decimals) {string regex = ' \\-?[ 
1-9]\\d+ (\\.\\d+)? "; 
Return pattern.matches (regex,decimals);  /** * Verify White-space characters * @param blankspace White-space characters, including: spaces, \ \ n, \ r, \f, \x0b * @return Validation returns true successfully, validation failure returns false */public static Boolean 
Checkblankspace (String blankspace) {string regex = ' \\s+ '; 
Return pattern.matches (Regex,blankspace); /** * Verify that Chinese * @param Chinese characters * @return validation returns true successfully, validation fails return false/public static Boolean Checkchinese (String Chinese 
{String regex = ' ^[\u4e00-\u9fa5]+$ '; 
Return pattern.matches (Regex,chinese); /** * Validation date (month/year) * @param birthday date, format: 1992-09-03, or 1992.09.03 * @return validation returns true successfully, validation fails return false/public static Boole 
An checkbirthday (string birthday) {string regex = "[1-9]{4} ([-./]) \\d{1,2}\\1\\d{1,2}"; 
Return pattern.matches (Regex,birthday); /** * Verify URL address * @param URL format: http://blog.csdn.net:80/xyang81/article/details/7705960? or http://www.csdn.net:80 * @return validation successfully returns true, validation fails to return FALSE */public static Boolean checkurl (string url) {string regex = ' (https?:/ /(w{3}\\.)? \\w+\\.\\w+ (\\.[ a-za-z]+) * (: \\d{1,5})? (/\\w*) * (\??) (.+=.*)? 
(&.+=.*)? "; 
Return pattern.matches (regex, url); /** * <pre> * Get URL of the first level domain name * http://www.zuidaima.com/share/1550463379442688.htm->> zuidaima.com * </p re> * * @param URL * @return/public static String getdomain (string url) {Pattern p = pattern.compile (? <=http: //|\\.) [^.] *?\\.
(COM|CN|NET|ORG|BIZ|INFO|CC|TV) ", pattern.case_insensitive); Get the full domain name//pattern P=pattern.compile ("[^//]*?\\.
COM|CN|NET|ORG|BIZ|INFO|CC|TV) ", pattern.case_insensitive);
Matcher Matcher = p.matcher (URL);
Matcher.find ();
return Matcher.group (); /** * Matching China postal code * @param postcode postal code * @return Validation returns true successfully, validation fails return false */public static Boolean Checkpostcode (String PO 
Stcode) {String regex = ' [1-9]\\d{5} '; 
Return Pattern.matches (regex, postcode); /** * Match IP address (simple match, format, such as: 192.168.1.1,127.0.0.1, no matching IP segment size) * @param ipaddress IPV4 standard address * @return validatedWork returns TRUE, validation failure returns false */public static Boolean checkipaddress (String ipaddress) {string regex = ' [1-9] (\\d{1,2})? \. ( 0| ([1-9] (\\d{1,2})) \\. (0| ([1-9] (\\d{1,2})) \\. (0| 
([1-9] (\\d{1,2})) "; 
Return pattern.matches (Regex, IPAddress); } 
}

The above is a small set for everyone to share the Java random password generation and and mailbox, mobile phone matching related content, I hope to help.

Related Article

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.