博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
邮箱验证信息
阅读量:6965 次
发布时间:2019-06-27

本文共 855 字,大约阅读时间需要 2 分钟。

第一种是普通常规的验证方法:

1         //邮箱的验证,验证内容:1、是否有@符号,不能在开始位置,2、是否有.符号,不能在最后位置;3、@符号是否在.号前面2         System.out.println("请输入邮箱:");3         String email=input.nextLine();4         //普通的验证合法性5         if(email.indexOf("@")<0 || email.startsWith("@") || email.indexOf(".")<0 || email.endsWith(".") || email.indexOf("@")>email.lastIndexOf(".")){6             System.out.println("不合法");7         }else{8             System.out.println("合法");9     }

第二种是用正则表达式表示的:

使用正则表达式的方式验证合法性	 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 match=pattern.matcher(email);		if(match.matches()){			System.out.println("合法");		}else{			System.out.println("不合法");		}				for(int i=0;i

 

转载于:https://www.cnblogs.com/zhuangjixiang/archive/2012/11/27/2791341.html

你可能感兴趣的文章
iOS 13 上手体验
查看>>
个人笔记
查看>>
【题解】 CF949C Data Center Maintenance
查看>>
【第四期】基于 @vue/cli3 插件,集成日志系统【SSR第三篇】
查看>>
命令类型即使用帮助
查看>>
struts2中不能使用static关键字作为URL路径
查看>>
SQL Sever 学习系列之三
查看>>
Cannot determine embedded database driver class for database type NONE
查看>>
解决Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!
查看>>
iOS多线程-NSThread
查看>>
linux安装sphinx
查看>>
1.0、Android Studio管理你的项目
查看>>
Web.py Cookbook 简体中文版
查看>>
使用 Bullet,BulletManager 在 XNA 中创建子弹攻击目标(十五)
查看>>
python中的sort方法使用详解
查看>>
用户问卷算法加前台处理
查看>>
学习记录:CONCAT()
查看>>
mysql 递归查询 主要是对于层级关系的查询
查看>>
iOS 文件的操作
查看>>
函数指针的使用
查看>>