問題描述:
解析一個郵箱地址是否合法,如果合法則打印出用戶名部分和該郵箱所屬的網(wǎng)站域名
如果郵箱地址不合法則顯示不合法的原因
提示:郵箱地址不合法的因素:
1)郵箱地址中不包含@或。
2)郵箱地址中含有多了@或。
3)郵箱地址中。出現(xiàn)在@的前面
4)用戶名里有其他字符
實現(xiàn)步驟:
類圖如下:
import java.util.Scanner; public class MailTest { /* * 1.地址中不包括@ 或 . * 2.地址中包括多個 @ 或 . * 3.郵箱地址中 . 出現(xiàn) 在@ 前面 * 4.用戶名中出現(xiàn)其他字符 */ public static boolean testMail() { Scanner sc = new Scanner(System.in); String strMail = sc.nextLine(); if(strMail.indexOf("@") == -1 || strMail.indexOf(".") == -1) { System.out.println("1"); return false; } if(strMail.indexOf("@") != strMail.lastIndexOf("@") || strMail.indexOf(".") != strMail.lastIndexOf(".")){ System.out.println("2"); return false; } if(strMail.indexOf("@")>strMail.indexOf(".")) { System.out.println("3"); return false; } for(int i = 0; i<strMail.indexOf("@"); i++) { if(!((strMail.charAt(i) > \'A\' && strMail.charAt(i) < \'Z\') || (strMail.charAt(i) > \'a\' && strMail.charAt(i) < \'z\'))) { System.out.println("4"); return false; } } return true; } }
網(wǎng)站欄目:Java-驗證郵箱地址是否符合要求
URL網(wǎng)址:http://aaarwkj.com/article24/chcjje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、關(guān)鍵詞優(yōu)化、電子商務(wù)、網(wǎng)站營銷、定制開發(fā)、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)