SWIFT中正则表达式验证邮箱
在playground内写入以下代码,正则关键字跟其它语言的没什么区别
class Regex {
let internalExpression:NSRegularExpression
let pattern:String init(pattern:String) {
self.pattern = pattern
var error:NSError?
self.internalExpression = NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive, error: &error)!
} func match(input:String) -> Bool {
let matches = self.internalExpression.matchesInString(input, options: nil, range: NSMakeRange(0, count(input)))
return matches.count > 0
}
} var email_regex = case Email = "^([a-zA-Z0-9]+([._\\-])*[a-zA-Z0-9]*)+@([a-zA-Z0-9])+(.([a-zA-Z])+)+$" var regex = Regex(pattern:email_regex) regex.match("service@t.com") //RETURN true
regex.match("ken.ngai@tao.com.cn") //RETURN true
regex.match("buddy_wei@frend.org") //RETURN true
CaseInsensitive:大小写不敏感
SWIFT中正则表达式验证邮箱的更多相关文章
- IOS开发中怎样验证邮箱的合法性
IOS开发中怎样验证邮箱的合法性 文章参考:http://www.codes51.com/article/detail_94157.html 代码: - (void)viewDidLoad { [su ...
- favicon.ico应用与正则表达式验证邮箱(可自动删除前后的空格)
1.favicon.ico制作:favicon.ico可以ps制作;“shortcut icon”中间有一个空格 <head> <link rel="shortcut ic ...
- web开发常用的js验证,利用正则表达式验证邮箱、手机、身份证等输入
正则表达式验证 //邮箱 \-])+\.)+([a-zA-Z0-]{,})+$/; email = document.getElementById("email").value; ...
- 面试题 正则表达式 验证邮箱 Pattern.matches
故事背景 今天面试遇到这道题,对正则表达式还是有些懵,面试完回家复盘实现一下.这里使用到了 Pattern 这个类来校验正则表达式. 正则表示式分析: ^([a-z0-9A-Z]+[-|\\.]?)+ ...
- js中通过正则表达式验证邮箱是否合法
文章目录 1.效果展示 2.问题描述 3.代码实现 1.效果展示 2.问题描述 当用户在输入框输入邮箱后.点击验证邮箱按钮.系统给出提示信息. 3.代码实现 <!DOCTYPE html> ...
- jQuery邮箱验证正则表达式验证邮箱合法
if($.trim(email)==''||$.trim(email)=='邮 箱:'||$.trim(email)==null){ alert('邮箱不能为空!'); return false ...
- Android 使用正则表达式验证邮箱格式是否正确
/** * 验证邮箱格式是否正确 */ public boolean emailValidation(String email) { String regex = "\\w+([-+.]\\ ...
- java正则表达式验证邮箱、手机号码
/** * 验证邮箱地址是否正确 * @param email * @return */ public static boolean checkEmail(String email){ boolean ...
- javascript平时小例子②(正则表达式验证邮箱)
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>邮 ...
随机推荐
- html 表格中添加圆
效果: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" con ...
- 寻找重复的子树 Find Duplicate Subtrees
2018-07-29 17:42:29 问题描述: 问题求解: 本题是要求寻找一棵树中的重复子树,问题的难点在于如何在遍历的时候对之前遍历过的子树进行描述和保存. 这里就需要使用之前使用过的二叉树序列 ...
- Python map/reduce
2017-07-31 18:20:59 一.map函数 map():会根据提供的函数对指定序列做映射.第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 ...
- IIS中发布后出现Could not load file or assembly'System.Data.SQLite.dll' or one of its depedencies
[问题]在我本机的开发环境c#连接sqlite3没有问题,可是release版本移植到其他的机器就提示Could not load file or assembly'System.Data.SQLit ...
- Oracle 起诉 Google 事件
最近,Google 和 Oracle 纠缠多年的“Java 侵权案”又有了新的判决结果.Google 在此次对决中败诉,并可能需要支付高达88亿美元的赔偿金.这个案件还引发关于 API(应用程序编程接 ...
- windows 命令巧用(持续更新)
netstat -ano netstat -anvb netstat -s -p [tcp|udp|ip|icmp] # 关闭/打开防火墙 netsh firewall set opmode disa ...
- 多线程(JDK1.5的新特性互斥锁)
多线程(JDK1.5的新特性互斥锁)(掌握)1.同步·使用ReentrantLock类的lock()和unlock()方法进行同步2.通信·使用ReentrantLock类的newCondition( ...
- CentOS 配置Tomcat服务脚本
#!/bin/bash # description: Tomcat7 Start Stop Restart # processname: tomcat7 # chkconfig: JAVA_HOME= ...
- hpu1165 贪心
1165: 最少的需求 [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 12 解决: 4 状态 题目描述 小Q开了一家餐厅,最近生意非常火爆. 假设有N N 个预订信息,第i i ...
- OC MRC之循环引用问题(代码分析)
// // main.m // 07-循环引用 // // Created by apple on 13-8-9. // Copyright (c) 2013年 itcast. All rights ...