JavaScript系列:正则表达式
2016-03-21 12:17
483 查看
function testExecResultType() { var txt = "mom and dad and baby"; var pattern = /mom (and day (and baby)?)?/ig; var match = pattern.exec(txt); document.writeln("<br>match's type is instanceof array:" + (match instanceof Array)); document.writeln("<br>Array.isArray(matches):" + Array.isArray(match)); } function testTelNum() { var p1 = /^1\d{10}$/g; var pattern = new RegExp(p1.source, "g"); var telNum1 = "13088888888"; var telNum2 = "13300008888"; document.writeln("<br>" + telNum1 + " is telNum:" + pattern.test(telNum1)); pattern.lastIndex = 0; document.writeln("<br>" + telNum2 + " is telNum:" + pattern.test(telNum2)); } function testIfIsPatternObjectIsGlobal() { var p = /\w+@\w+\.com/g; var mail = "zhangsan@amail.com"; document.writeln("<br>" + mail + " is mail?" + p.test(mail)); document.writeln("<br>lastIndex: " + p.lastIndex); p = /^1\d{10}/g; document.writeln("<br>lastIndex: " + p.lastIndex); var telNum = "13088888888"; document.writeln("<br>" + telNum +" is telNum? " + p.test(telNum)); } testIfIsPatternObjectIsGlobal(); //testTelNum(); //testExecResultType();
相关文章推荐
- js 跨域访问
- JS实现数字千位符格式化方法
- js操作select
- 7、JSONArray的应用
- ExtJs中组件最好少使用ID属性(推荐更多使用Name属性)
- Map 转 JSON
- JSON 转Map
- .net json序列化组件Json.NET(Newtonsoft.Json)
- js函数的参数
- js获取对象的属性和方法总结
- js实现trim() JS去掉首尾空格 JS去掉两头空格
- 常用JS表单验证函数
- js如何判断访问是来自搜索引擎(蜘蛛人)还是直接访问?
- 百度蜘蛛爬行js文件能否完全识别js代码
- 如何实现JS_MD5加密(2013-
- js 手机,pad,电脑,客户端判断跳转。。
- js调用中文乱码问题
- js 屏蔽鼠标右键,复制,黏贴,保存
- <a>标签中href=\"javascript:;\"表示什么意思??
- js 如何获得ckeditor的值