手機號 郵箱等驗證

來源:互聯網
上載者:User

標籤:

package com.hengxin.qianee.utils;

import java.net.InetAddress;

public class RegexUtils {

/**
* 使用者名稱是否符合規範(^[\u4E00-\u9FA5A-Za-z0-9_]+$)
* @return
*/
public static boolean isValidUsername(String username) {
if (username==null || username.trim() == "") {
return false;
}

return username.matches("^[\u4E00-\u9FA5A-Za-z0-9_]{2,10}$");
}

/**
* 密碼是否符合規範([a-zA-Z\d]{6,20})
* @return
*/
public static boolean isValidPassword(String password) {
if (null == password) {
return false;
}

return password.matches("^([^\\s‘‘’]{6,20})$");
}
//public static boolean isValidPassword(String password) {
//if (null == password) {
//return false;
//}
//
//return password.matches("[a-zA-Z\\d]{6,20}");
//}
/**
* 是否有效手機號碼
* @param mobileNum
* @return
*/
public static boolean isMobileNum(String mobileNum) {
if (null == mobileNum) {
return false;
}

return mobileNum.matches("^((13[0-9])|(14[4,7])|(15[^4,\\D])|(17[6-8])|(18[0-9]))(\\d{8})$");
}

/**
* 是否有效郵箱
* @param email
* @return
*/
public static boolean isEmail(String email) {
if (null == email) {
return false;
}

return email.matches("^([a-zA-Z0-9])+([a-zA-Z0-9_.-])[email protected]([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$");
}

/**
* 是否是QQ郵箱
*/
public static boolean isQQEmail(String email){
if(null == email)
return false;

return email.matches("^[\\s\\S]*@qq.com$");
}

/**
* 是否數字(小數||整數)
* @param number
* @return
*/
public static boolean isNumber(String number) {
if (null == number) {
return false;
}

return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d)+)?$");
}

/**
* 是否整數
* @param number
* @return
*/
public static boolean isInt(String number) {
if (null == number) {
return false;
}

return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))$");
}

/**
* 是否正整數
* @param number
* @return
*/
public static boolean isPositiveInt(String number) {
if (null == number) {
return false;
}

return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))$");
}

/**
* 是否日期yyyy-mm-dd(yyyy/mm/dd)
* @param date
* @return
*/
public static boolean isDate(String date) {
if (null == date) {
return false;
}
return date.matches("^([1-2]\\d{3})[\\/|\\-](0?[1-9]|10|11|12)[\\/|\\-]([1-2]?[0-9]|0[1-9]|30|31)$");
}

/**
* 逗號分隔的Regex
* @param str
* @return
*/
public static String getCommaSparatedRegex(String str) {
if (str == null) {
return null;
}

return "^("+str+")|([\\s\\S]*,"+str+")|("+str+",[\\s\\S]*)|([\\s\\S]*,"+str+",[\\s\\S]*)$";
}

/**
* 字串包含
* @return
*/
public static boolean contains(String str, String regex) {
if (str == null || regex == null) {
return false;
}

return str.matches(regex);
}

/**
* 是否為16,19或者22位銀行帳號
* @param bankAccount
* @return
*/
public static boolean isBankAccount(String bankAccount){
if (null == bankAccount) {
return false;
}

return bankAccount.matches("^(\\d{19}|\\d{16}|\\d{22})$");
}

/**
* 擷取本機IP
* @return
*/
public static String getIp(){

InetAddress ia=null;
try {
ia=ia.getLocalHost();

String localip=ia.getHostAddress();
//String localname=ia.getHostName();
//System.out.println("本機名稱:"+ localname);
//System.out.println("原生ip :"+localip);

return localip;
} catch (Exception e) {
e.printStackTrace();
}

return "127.0.0.1";
}

}

手機號 郵箱等驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.