/**
* 驗證手機號碼
* * @author dujiayu
* @time 2023年4月25日11:12:57
*/public
class
numberutil$";
// 用於匹配固定**號碼
private
final
static string regex_fixedphone =
"^(010|02\\d|0[3-9]\\d)?\\d$"
;// 用於獲取固定**中的區號
private
final
static string regex_zipcode =
"^(010|02\\d|0[3-9]\\d)\\d$"
;private
static pattern pattern_mobilephone;
private
static pattern pattern_fixedphone;
private
static pattern pattern_zipcode;
static
public
enum phonetype
public
static
class
numbers
public phonetype gettype()
public string getcode()
public string getnumber()
@override
public string tostring()
}/**
* 判斷是否為手機號碼
** @param number 手機號碼
* @return
*/public
static
boolean
iscellphone
(string number)
/** * 判斷是否為固定**號碼
** @param number 固定**號碼
* @return
*/public
static
boolean
isfixedphone
(string number)
/** * 獲取固定號碼號碼中的區號
** @param strnumber
* @return
*/public
static string getzipfromhomephone
(string strnumber)
return null;
}/**
* 檢查號碼型別,並獲取號碼字首,手機獲取前7位,固話獲取區號
** @param _number
* @return
*/public
static numbers checknumber
(string _number)
rtnum =
newnumbers
(phonetype.cellphone, number.
substring(0
,7), _number);}
elseif(
isfixedphone
(number)
)else
}return rtnum;
}}
手機號碼驗證
正規表示式的使用 正規表示式的元素符及其意義 元素符正規表示式中的寫法意義.代表任意乙個字元 d d 代表0 9的任意乙個數字 d d 代表任何乙個非數字字元 s s 代表空白字元,如 t n s s 代表非空白字元 w w 代表可用作識別符號的字元,但不包括 符 w w 代表不可用於識別符號的字元...
工具類 手機號碼校驗
方便自己下次使用。public class checkphone d d d 中國電信號碼格式驗證 手機段 133,153,180,181,189,177,1700,173 private static final string china telecom pattern 1 33 53 7 37 ...
手機號碼最新驗證
由於手機號段的不斷更新,以前的正規表示式已經無法滿足需求。重新編寫這條表示式12 3varregex 表示式分析 代表乙個正規表示式。代表字串的開始位置,代表字串的結束位置。代表匹配前面的字元乙個或零個,所以這裡0?的意思是手機號碼可以以0開頭或不以0開頭。接下的部分驗證11位的手機號碼,先從13開...