Javaランダムパスワードを生成し、メールボックス、携帯電話番号と一致させる

6812 ワード

くだらない話は多くなくて、直接みんなにjavaコードを貼って、コードは注釈があって、書くのがよくなくて、またみんなによろしくお願いします.
コードは次のとおりです.

package com.alibaba.uyuni.common.util;
import java.util.Random;
public class GeneratePassword {
/**
*       
* @param pwd_len
*          
* @return       
*/
public static String genRandomNum(int pwd_len) {
// 26*2   +10   
final int maxNum = 62;
int i; //       
int count = 0; //         
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("");
Random r = new Random();
while (count < pwd_len) {
//      ,    ,      ,
i = Math.abs(r.nextInt(maxNum)); //        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 {
/**
*   Email
* @param email email  ,  :[email protected][email protected],xxx       
* @return       true,      false
*/ 
public static boolean checkEmail(String email) { 
String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?"; 
return Pattern.matches(regex, email); 
} 
/**
*   ***  
* @param idCard   ***  15  18 ,            
* @return       true,      false
*/ 
public static boolean checkIdCard(String idCard) { 
String regex = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}"; 
return Pattern.matches(regex,idCard); 
} 
/**
*       (      ,+86135xxxx...(    ),+00852137xxxx...(    ))
* @param mobile   、  、         
*

:134(0-8)、135、136、137、138、139、147( TD ) *、150、151、152、157(TD )、158、159、187( )、188(TD )

*

:130、131、132、155、156( )、185( )、186(3g)

*

:133、153、180( )、189

* @return true, false */ public static boolean checkMobile(String mobile) { String regex = "(\\+\\d+)?1[3458]\\d{9}$"; return Pattern.matches(regex,mobile); } /** * * @param phone , : ( ) + ( ) + , :+8602085588447 *

( ) : ( ) ( ) 。 0 9 , * ( ) 。

*

( ): 0 9 , ―― * ( ), 。

*

0 9

* @return true, false */ public static boolean checkPhone(String phone) { String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$"; return Pattern.matches(regex, phone); } /** * ( ) * @param digit 0-9 * @return true, false */ public static boolean checkDigit(String digit) { String regex = "\\-?[1-9]\\d+"; return Pattern.matches(regex,digit); } /** * ( ) * @param decimals 0-9 , :1.23,233.30 * @return true, false */ public static boolean checkDecimals(String decimals) { String regex = "\\-?[1-9]\\d+(\\.\\d+)?"; return Pattern.matches(regex,decimals); } /** * * @param blankSpace , : 、\t、
、\r、\f、\x0B * @return true, false */ public static boolean checkBlankSpace(String blankSpace) { String regex = "\\s+"; return Pattern.matches(regex,blankSpace); } /** * * @param chinese * @return true, false */ public static boolean checkChinese(String chinese) { String regex = "^[\u4E00-\u9FA5]+$"; return Pattern.matches(regex,chinese); } /** * ( ) * @param birthday , :1992-09-03, 1992.09.03 * @return true, false */ public static boolean checkBirthday(String birthday) { String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}"; return Pattern.matches(regex,birthday); } /** * URL * @param url :http://blog.csdn.net:80/xyang81/article/details/7705960? http://www.csdn.net:80 * @return true, 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); } /** *

*      URL      
* http://www.zuidaima.com/share/1550463379442688.htm ->> zuidaima.com
* 
*
* @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);
// なドメイン の
//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();
}
/**
* に
*@param postcode
*@return はtrueを に し、 に してfalseを します.
*/
public static boolean checkPostcode(String postcode) {
String regex = "[1-9]\\d{5}";
return Pattern.matches(regex, postcode);
}
/**
*マッチングIPアドレス( マッチング、フォーマット、 えば:192.168.1.1.12127.0.1、マッチングIPセグメントのサイズがない)
*@param ipAddress IPv 4 アドレス
*@return はtrueを に し、 に して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);
}
}
、 が したJavaランダムパスワードを し、メールボックスや と させる をご しましたので、お に てばと います.