Regex – java驗證IP地址 – java驗證日期時間,解決潤月 – java驗證郵箱格式

來源:互聯網
上載者:User
1.java驗證IP地址:

Pattern pattern = Pattern.compile("//b((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//b");

Matcher matcher = pattern.matcher("127.400.600.2"); //以驗證127.400.600.2為例

System.out.println(matcher.matches());

2. java驗證日期時間,解決潤月:

Pattern pattern = Pattern.compile("^((//d{2}(([02468][048])|([13579][26]))[//-/////s]?((((0?[13578])|(1[02]))[//-/////s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[//-/////s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[//-/////s]?((0?[1-9])|([1-2][0-9])))))|(//d{2}(([02468][1235679])|([13579][01345789]))[//-/////s]?((((0?[13578])|(1[02]))[//-/////s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[//-/////s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[//-/////s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(//s(((0?[0-9])|([1-2][0-3]))//:([0-5]?[0-9])((//s)|(//:([0-5]?[0-9])))))?$");

Matcher matcher = pattern.matcher("2000-02-29 23:59:59");

System.out.println(matcher.matches());

3.java驗證郵箱格式:

Pattern pattern = Pattern.compile("^([a-zA-Z0-9_//-//.]+)@((//[[0-9]{1,3}//.[0-9]{1,3}//.[0-9]{1,3}//.)|(([a-zA-Z0-9//-]+//.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(//]?)$");

Matcher matcher = pattern.matcher("a@aa.com");

System.out.println(matcher.matches());

一般遇到要設計該類運算式,需要先找現成的,自己很難設計出有用的運算式,除非去深入研究了,好了以上的一些運算式花了不少時間,在這裡謝謝群裡的好友,謝謝你們耐心的協助,真的謝謝了,拿出來分享下,要的頂下·····

 
 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.