Generate random password and mailbox, phone match

Source: Internet
Author: User

package com.alibaba.uyuni.common.util;import java.util.random;public class  generatepassword {    /**     *  Generate random passwords       *  @param  pwd_len     *  Total length of passwords generated       *  @return   Password Strings      */    public  Static string genrandomnum (Int pwd_len)  {        / / 26*2 Letters + 10 digits         final int maxNum = 62; Random numbers generated by         int i; //           int count = 0; //  the length of the password generated          char[] str = {  ' 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 ',  ' 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 ("");    &nbsP;    random r = new random ();         while  (Count < pwd_len)  {             //  generate random numbers, take absolute values, and prevent negative numbers from being generated,             i = math.abs (R.nextint (maxnum)); //  generates the largest number of 62-1             if  (i >= 0 && 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 {     /**      *  Verify email     *  @param  email email address, format: [email  protected],[email protected],xxx on behalf of mail service providers      *  @return   Verify successful return True , validation failed to return False     */     public static boolean  checkemail (String email)  {         String  regex =  "\\[email protected]\\w+\\. [A-z]+ (\\.[ a-z]+)? ";          return pattern.matches (Regex, email);      }          /**      *  Verify * * * Number      *  @param  idcard&nbsP; * * * Number 15 or 18 digits, the last one may be a number or a letter      *  @return   Verify success returns True, validation failed to return false      */     public static boolean checkidcard ( 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's number segment       *<p> Mobile Number segment: 134 (0-8), 135, 136, 137, 138, 139, 147 (expected for TD card)      *, 150, 151, 152, 157 (TD-only), 158, 159, 187 (not enabled), 188 (TD-specific) </p>     *<p> Unicom number segment: 130, 131, 132, 155, 156 (World Wind Only), 185 (not enabled), 186 (3g) &LT;/P&GT;&NBSP;&NBsp;   *<p> Telecom Number segment: 133, 153, 180 (not enabled), 189</p>     * @ return  validation returns True, validation failed to return false     */     public  Static boolean checkmobile (String mobile)  {          String regex =  "(\\+\\d+) 1[3458]\\d{9}$";          return pattern.matches (Regex,mobile);     }           /**     *  Verify fixed Phone numbers       *  @param  phone  phone number, Format: country/Region Phone code  +  area code  +  phone 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 ,     *   digits followed by a space-delimited country/region code. </p>   &nbSp; * <p><b> Area code:</b> This may contain one or more numbers from  0  to  9 , area or city code placed in parentheses--      *  omit this component for countries (regions) that do not use a region or city code. </p>     * <p><b> Phone number:</b> This includes from  0  to  9   One or more digits  </p>     *  @return   Validation returns true successfully, validation failed to return false      */     public static 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  One or more digits between 0-9 integers      *  @return &nbSP; validation returns true, validation failed to return false     */     public static  boolean checkdigit (string digit)  {          string regex =  "\\-? [1-9]\\d+];          return pattern.matches (regex,digit);      }          /**      *  verifying integers and floating-point numbers (plus and minus integers and positive and negative floating-point numbers)      *  @param  decimals  One or more 0-9 floating-point numbers, such as:1.23,233.30     *  @return   Verify success returns true, validation fails to return false      */     public static boolean checkdecimals ( String decimals)  {         string regex =   "\\-? [1-9]\\d+ (\\.\\d+)? ";          return pattern.matcheS (regex,decimals);     }            /**     *  verify whitespace characters      *  @param   blankspace  whitespace characters, including: spaces, \ t, \ n, \ r, \f, \x0b     *  @return   Verify successful return True, Validation failed to return false     */     public static boolean  Checkblankspace (String blankspace)  {         string  regex =  "\\s+";         return  Pattern.matches (Regex,blankspace);     }           /**     *  Verify Chinese      *  @param  chinese  Chinese characters      *  @return   validation returns true successfully, validation failed to return false      */     publIc static boolean checkchinese (String chinese)  {          String regex =  "^[\u4e00-\u9fa5]+$";          return pattern.matches (Regex,chinese);     }           /**     *  Verification Date (Month day)       *  @param  birthday  Date, format: 1992-09-03, or 1992.09.03     *  @return   Verify success returns True, validation failed to return false     */     public  Static boolean checkbirthday (String birthday)  {          String regex =  "[1-9]{4} ([-./]) \\d{1,2}\\1\\d{1,2}";          return pattern.matches (Regex,birthday);     }           /**     *  Verify the URL address      *   @param  url  format:http://blog.csdn.net:80/xyang81/article/details/7705960?  or  http:// www.csdn.net:80     *  @return   Verify success returns True, validation failed 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  URL  first-level domain name       * http://www.zuidaima.com/share/1550463379442688.htm ->> zuidaima.com     * </pre>     *       *  @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 postcode       *  @param  postcode  Postal Code      *  @return   Verify success returns TRUE, validation failure returns false      */     public static boolean  Checkpostcode (String postcode)  {         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   Verify success returns True, validation failed to return 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);      }      }



This article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1737792

Generate random password and mailbox, phone match

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.