|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
The following code is a sample of some characters you can check are in an email address, or should not be in an email address. It is not a complete email validation program that checks for all possible email scenarios, but can be added to as needed. /* * Checks for invalid characters * in email addresses */ public class EmailValidation { public static void main(String[] args) throws Exception { String input = "@sun.com"; //Checks for email addresses starting with //inappropriate symbols like dots or @ signs. Pattern p = Pattern.compile("^.|^@"); Matcher m = p.matcher(input); if (m.find()) System.err.println("Email addresses don´t start" + " with dots or @ signs."); //Checks for email addresses that start with //www. and prints a message if it does. p = Pattern.compile("^www."); m = p.matcher(input); if (m.find()) { System.out.println("Email addresses don´t start" + " with "www.", only web pages do."); } p = Pattern.compile("[^A-Za-z0-9.@_-~#]+"); m = p.matcher(input); StringBuffer sb = new StringBuffer(); boolean result = m.find(); boolean deletedIllegalChars = false; while(result) { deletedIllegalChars = true; m.appendReplacement(sb, ""); result = m.find(); } // Add the last segment of input to the new String m.appendTail(sb); input = sb.toString(); if (deletedIllegalChars) { System.out.println("It contained incorrect characters" + " , such as spaces or commas."); } } } 返回类别: 教程 上一教程: JSP开发入门(三)--JSP与JAVABEAN 下一教程: 用JAVA程序取得IP地址 您可以阅读与"JSP中EMAIL格式的判定"相关的教程: · JSP三种页面跳转方法的比较 · 用JSP实现类似资源治理器式的文件与目录的折叠 · 读取foxpro格式的dbf文件 · 使用DateFormat类输出各种格式的时间(上) · JSP结合XML+XSLT将输出转变为HTML格式 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |