Saya tidak akan mengatakan banyak omong kosong, saya hanya akan memposting kode java untuk Anda. Kode telah dikomentari dan tidak ditulis dengan baik. Tolong jaga itu.
Kode terlihat seperti ini:
package com.alibaba.uyuni.common.util;import java.util.Random;public class GeneratePassword {/*** Generate random password* @param pwd_len* Total length of generated password* @return Password string*/public static String genRandomNum(int pwd_len) {// 26*2 letters + 10 numbers final int maxNum = 62;int i; // Hasilkan jumlah int ac acak = 0; // Length of generated password 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 (""); acak r = acak baru (); while (count <pwd_len) {// menghasilkan nomor acak, ambil nilai absolut, dan mencegah angka negatif dari yang dihasilkan, saya = matematika. // Nomor maksimum yang dihasilkan adalah 62-1if (i> = 0 && i <str.length) {pwd.append (str [i]); count ++;}} return pwd.toString ();} public static void main (string [] args) {System.out.println (GenRandomnum (String [] args) {System.out.println (GenRandomnum) com.alibaba.uyuni.common.util; import java.util.regex.matcher; import java.util.regex.pattern; kelas publik regexutils {/*** Verifikasi email* @param alamat email, format: [email protected], zhangsan @params, format: [email protected], zhangsan @param.pormat: zhangsn. Verifikasi pengembalian true, dan verifikasi gagal mengembalikan false*/public static boolean checkemail (email string) {string regex = "//w+@//w+//.htaz media+(//.htazilai)?"; pengembalian pola.matches (regex, email); } /*** Verification *** number* @param idCard Resident *** number 15 or 18 digits, the last digit may be a number or letter* @return Return true for successful verification, and false for failure verification*/ public static boolean checkIdCard(String idCard) { String regex = "[1-9]//d{13,16}[a-zA-Z0-9]{1}"; return pola.matches (regex, idcard); } /*** Verifikasi Nomor Ponsel (Mendukung Format Internasional, +86135xxxx ... (daratan Cina), +00852137xxxx ... (Hong Kong, Cina))*@param Nomor Ponsel dari Mobile, China Unicom, dan Operator Telekomunikasi*<P> Segment Nomor Ponsel: 134, 134) (0-8), 136), 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, untuk kartu jaringan TD)*, 150, 151, 152, 157 (TD berdedikasi), 158, 159, 187 (tidak diaktifkan), 188 (TD berdedikasi) </p>*<p> Segmen Nomor Telpu Telp: 130, 131, 132, 155, P> </P> </P -PETICE DUKUNGAN DUNIA), 185 (bukan Engening), 132, 186, PP WIND (PEW), PER -131 (PERM), PER -132 (PRANT/155 (PREC) (PRANT 131 (PRANT/BUKAN, 133, 153, 180 (tidak diaktifkan), 189 </p>* @Return verifikasi berhasil dan pengembalian true, dan verifikasi gagal dan mengembalikan false*/public static boolean checkMobile (string seluler) {string regex = "(//+// d+)? 1 [3458] // d {9} $"; return Pattern.matches (Regex, Mobile); } /*** Verifikasi nomor telepon rumah* @param Nomor telepon, format: negara (wilayah) kode telepon + kode area (kode kota) + nomor telepon, seperti: + 8602085588447* <p> <b> Kode negara (wilayah): </b> kode negara standar (wilayah) yang mengidentifikasi negara (wilayah) dari nomor telepon. Ini berisi satu atau lebih digit dari 0 hingga 9, diikuti oleh kode negara yang dipisahkan ruang. </p>* <p> <b> Kode Area (Kode Kota): </b> Ini mungkin berisi satu atau lebih angka dari 0 hingga 9, dan wilayah atau kode kota ditempatkan dalam tanda kurung -* Komponen ini dihilangkan untuk negara (wilayah) yang tidak menggunakan wilayah atau kode kota. </p>* <p> <b> Nomor telepon: </b> Ini berisi satu atau lebih nomor dari 0 hingga 9 </p>* @return kembali true ketika verifikasi berhasil, dan mengembalikan false*/public static boolean checkphone (string phone) {string regex = "(//+// d+)? (// d {3,4}; pengembalian pola.matches (regex, telepon); }/*** Verifikasi bilangan bulat (bilangan bulat positif dan bilangan bulat negatif)* @param digit bilangan bulat antara satu atau lebih bit 0-9* @return kembali benar ketika verifikasi berhasil, mengembalikan false*/public static boolean checkDigit (string digit) {string regex = "//-? [1-9] // d+"; return pola.matches (regex, digit); } /*** Verify integers and floating-point numbers (positive and negative integers and positive and negative floating-point numbers)* @param decimals Floating-point numbers between one or more bits 0-9, such as: 1.23, 233.30* @return Verify returns true, and fails to verify, and return false*/ public static boolean checkDecimals(String decimals) { String regex = "//-? media1-9 bah//d+(//./d+)?"; Pola pengembalian.Matches (regex, desimal); } /*** Verify whitespace characters* @param blankSpace Whitespace characters, including: space, /t, /n, /r, /f, /x0B* @return Return true for successful verification, return false, fail to verify, return false*/ public static boolean checkBlankSpace(String blankSpace) { String regex = "//s+"; Pola pengembalian.Matches (Regex, Blankspace); }/*** Verifikasi Cina* @param karakter Cina Cina* @Return kembali benar untuk verifikasi yang berhasil, kembalikan false*/public static boolean checkchinese (string cina) {string regex = "^[/u4e00-/u9fa5]+$"; pengembalian pola.matches (Regex, Cina); } / *** Tanggal Verifikasi (Tahun, Bulan, Hari)* @param Tanggal Ulang Tahun, Format: 1992-09-03, atau 1992.09.03* @Return Verifikasi Pengembalian Benar, Verifikasi Gagal Mengembalikan False* / Public Static Boolean CheckBirthDay (String Birthdayes) {String regex = "[1-9] {4} ([-./]) // d {1,2} // 1 // d {1,2}"; return pola.matches (regex, ulang tahun); }/*** Alamat URL Verifikasi* @param URL Format: http://blog.csdn.net:80/xyang81/article/details/7705960? atau http://www.csdn.net:80* @return kembali benar ketika verifikasi berhasil, dan salah ketika verifikasi gagal, public static boolean checkUrl (string url) {string regex = "(https?: // (w {3} //.)?)? // w+//. // w+(//. [a-za-z]+)*(: // d {1,5})? (/// w*)*(// ?? (.+=.*)? (&.+=. return pola.matches (regex, url); }/*** <pr Pre>* Dapatkan nama domain tingkat pertama dari URL URL* http://www.zuidaima.com/share/1550463794426888.htm ->> zuidaima.com* </seter>* @param url* @return* public get static static static static static static static static static static static static static static static static static static static static static static public static public static public static public static public static public static public static public static public Static public static static public static public static public gets Pola.compile ("(? <= Http: // | //.) [^.]*? //. (Com | cn | net | org | biz | info | cc | tv)", pola.case_insensitive); // dapatkan nama domain // pola p = POLA PERCOLA ("[^//]*? //. Pattern.CASE_INSENSITIVE);Matcher matcher = p.matcher(url);matcher.find();return matcher.group();}/*** Match Chinese postcode* @param postcode Postcode* @return Verification is successful and returns true, and verification is failed and false*/ public static boolean checkPostcode(String postcode) { String regex = "[1-9] // d {5}"; return pola.matches (regex, postcode); } /*** Match IP address (simple match, format, such as: 192.168.1.1, 127.0.0.1, no matching size of the IP segment)* @param ipAddress IPv4 standard address* @return Verification is returned true, verification is failed, verification is returned 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})?)) //. (0 | ([1-9] (// d {1,2})?)) "; return pola.matches (regex, ipaddress); }}Di atas adalah konten yang relevan yang telah dibagikan oleh editor dengan Anda tentang pembuatan kata sandi acak Java dan mencocokkannya dengan email dan ponsel Anda. Saya harap ini akan membantu Anda.