JavaScript正则表达式检验与递归函数实际应用
//校验是否全由数字组成function isDigit(s){var patrn=/^[0-9]{1,20}$/;if (!patrn.exec(s)) return falsereturn true}//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;if (!patrn.exec(s)) return falsereturn true}//校验用户姓名:只能输入1-30个以字母开头的字串function isTrueName(s){var patrn=/^[a-zA-Z]{1,30}$/;if (!patrn.exec(s)) return falsereturn true}//校验密码:只能输入6-20个字母、数字、下划线function isPasswd(s){var patrn=/^(\w){6,20}$/;if (!patrn.exec(s)) return falsereturn true}//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”function isTel(s){//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//校验手机号码:必须以数字开头,除数字外,可含有“-”function isMobil(s){var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//校验邮政编码function isPostalCode(s){//var patrn=/^[a-zA-Z0-9]{3,12}$/;var patrn=/^[a-zA-Z0-9 ]{3,12}$/;if (!patrn.exec(s)) return falsereturn true}//校验搜索关键字function isSearch(s){var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;\'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;\'\,.<>?]{0,19}$/;if (!patrn.exec(s)) return falsereturn true}function isIP(s) //by zergling{var patrn=/^[0-9.]{1,20}$/;if (!patrn.exec(s)) return falsereturn true} * FUNCTION: isBetween* PARAMETERS: val AS any value* lo AS Lower limit to check* hi AS Higher limit to check* CALLS: NOTHING* RETURNS: TRUE if val is between lo and hi both inclusive, otherwise false. function isBetween (val, lo, hi) {if ((val < lo) || (val > hi)) { return(false); }else { return(true); }} * FUNCTION: isDate checks a valid date* PARAMETERS: theStr AS String* CALLS: isBetween, isInt* RETURNS: TRUE if theStr is a valid date otherwise false. function isDate (theStr) {var the1st = theStr.indexOf('-');var the2nd = theStr.lastIndexOf('-');if (the1st == the2nd) { return(false); }else {var y = theStr.substring(0,the1st);var m = theStr.substring(the1st+1,the2nd);var d = theStr.substring(the2nd+1,theStr.length);var maxDays = 31;if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {return(false); }else if (y.length < 4) { return(false); }else if (!isBetween (m, 1, 12)) { return(false); }else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;else if (m==2) {if (y % 4 > 0) maxDays = 28;else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;else maxDays = 29;}if (isBetween(d, 1, maxDays) == false) { return(false); }else { return(true); }}} * FUNCTION: isEuDate checks a valid date in British format* PARAMETERS: theStr AS String* CALLS: isBetween, isInt* RETURNS: TRUE if theStr is a valid date otherwise false. function isEuDate (theStr) {if (isBetween(theStr.length, 8, 10) == false) { return(false); }else {var the1st = theStr.indexOf('/');var the2nd = theStr.lastIndexOf('/');if (the1st == the2nd) { return(false); }else {var m = theStr.substring(the1st+1,the2nd);var d = theStr.substring(0,the1st);var y = theStr.substring(the2nd+1,theStr.length);var maxDays = 31;if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {return(false); }else if (y.length < 4) { return(false); }else if (isBetween (m, 1, 12) == false) { return(false); }else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;else if (m==2) {if (y % 4 > 0) maxDays = 28;else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;else maxDays = 29;}if (isBetween(d, 1, maxDays) == false) { return(false); }else { return(true); }}}} * FUNCTION: Compare Date! Which is the latest!* PARAMETERS: lessDate,moreDate AS String* CALLS: isDate,isBetween* RETURNS: TRUE if lessDate<moreDate function isComdate (lessDate , moreDate){if (!isDate(lessDate)) { return(false);}if (!isDate(moreDate)) { return(false);}var less1st = lessDate.indexOf('-');var less2nd = lessDate.lastIndexOf('-');var more1st = moreDate.indexOf('-');var more2nd = moreDate.lastIndexOf('-');var lessy = lessDate.substring(0,less1st);var lessm = lessDate.substring(less1st+1,less2nd);var lessd = lessDate.substring(less2nd+1,lessDate.length);var morey = moreDate.substring(0,more1st);var morem = moreDate.substring(more1st+1,more2nd);var mored = moreDate.substring(more2nd+1,moreDate.length);var Date1 = new Date(lessy,lessm,lessd); var Date2 = new Date(morey,morem,mored); if (Date1>Date2) { return(false);}return(true);} * FUNCTION isEmpty checks if the parameter is empty or null* PARAMETER str AS String function isEmpty (str) {if ((str==null)||(str.length==0)) return true;else return(false);} * FUNCTION: isInt* PARAMETER: theStr AS String * RETURNS: TRUE if the passed parameter is an integer, otherwise FALSE* CALLS: isDigit function isInt (theStr) {var flag = true;if (isEmpty(theStr)) { flag=false; }else{ for (var i=0; i<theStr.length; i++) {if (isDigit(theStr.substring(i,i+1)) == false) {flag = false; break;}}}return(flag);} * FUNCTION: isReal* PARAMETER: heStr AS String decLen AS Integer (how many digits after period)* RETURNS: TRUE if theStr is a float, otherwise FALSE* CALLS: isInt function isReal (theStr, decLen) {var dot1st = theStr.indexOf('.');var dot2nd = theStr.lastIndexOf('.');var OK = true;if (isEmpty(theStr)) return false;if (dot1st == -1) {if (!isInt(theStr)) return(false);else return(true);}else if (dot1st != dot2nd) return (false);else if (dot1st==0) return (false);else {var intPart = theStr.substring(0, dot1st);var decPart = theStr.substring(dot2nd+1);if (decPart.length > decLen) return(false);else if (!isInt(intPart) || !isInt(decPart)) return (false);else if (isEmpty(decPart)) return (false);else return(true);}} * FUNCTION: isEmail* PARAMETER: String (Email Address)* RETURNS: TRUE if the String is a valid Email address* FALSE if the passed string is not a valid Email Address* EMAIL FORMAT: AnyName@EmailServer e.g; webmaster@hotmail.com* @ sign can appear only once in the email address. function isEmail (theStr) {var atIndex = theStr.indexOf('@');var dotIndex = theStr.indexOf('.', atIndex);var flag = true;theSub = theStr.substring(0, dotIndex+1)if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) { return(false); }else { return(true); }} * FUNCTION: newWindow* PARAMETERS: doc -> Document to open in the new windowhite -> Height of the new windowwide -> Width of the new windowbars -> 1-Scroll bars = YES 0-Scroll Bars = NOresize -> 1-Resizable = YES 0-Resizable = NO* CALLS: NONE* RETURNS: New window instance function newWindow (doc, hite, wide, bars, resize) {var winNew="_blank";var opt="toolbar=0,location=0,directories=0,status=0,menubar=0,";opt+=("scrollbars="+bars+",");opt+=("resizable="+resize+",");opt+=("width="+wide+",");opt+=("height="+hite);winHandle=window.open(doc,winNew,opt);return;} * FUNCTION: DecimalFormat* PARAMETERS: paramValue -> Field value* CALLS: NONE* RETURNS: Formated string function DecimalFormat (paramValue) {var intPart = parseInt(paramValue);var decPart =parseFloat(paramValue) - intPart;str = "";if ((decPart == 0) || (decPart == null)) str += (intPart + ".00");else str += (intPart + decPart);return (str);}"^[0-9]*[1-9][0-9]*$" //正整数
"^((-\\d+)|(0+))$" //非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$" //负整数
"^-?\\d+$" //整数
"^\\d+(\\.\\d+)?$" //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$" //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
"^(-?\\d+)(\\.\\d+)?$" //浮点数
"^[A-Za-z]+$" //由26个英文字母组成的字符串
"^[A-Z]+$" //由26个英文字母的大写组成的字符串
"^[a-z]+$" //由26个英文字母的小写组成的字符串
"^[A-Za-z0-9]+$" //由数字和26个英文字母组成的字符串
"^\\w+$" //由数字、26个英文字母或者下划线组成的字符串
"^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$" //email地址
"^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$" //url
JavaScript正则表达式检验与递归函数实际应用的更多相关文章
- JavaScript -- 正则表达式 检验表单提交的内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JavaScript正则表达式检验手机号码、邮箱、ip地址等
1)检测IP地址的正则表达式 ((2 [0-4] \d | 25[0-5] | [01]?\d\d?) \.){3}(2 [0-4] \d | 25[0-5] | [01]?\d\d?) 2 [0-4 ...
- javascript正则表达式 - 学习笔记
JavaScript 正则表达式 学习笔记 标签(空格分隔): 基础 JavaScript 正则表达式是用于匹配字符串中字符组合的模式.在javascript中,正则表达式也是对象.这些模式被用于Re ...
- JavaScript正则表达式,你真的知道?
一.前言 粗浅的编写正则表达式,是造成性能瓶颈的主要原因.如下: var reg1 = /(A+A+)+B/; var reg2 = /AA+B/; 上述两个正则表达式,匹配效果是一样的,但是,效率就 ...
- 【JS】javascript 正则表达式 大全 总结
javascript 正则表达式 大全 总结 参考整理了一些javascript正则表达式 目的一:自我复习归纳总结 目的二:共享方便大家搜索 微信:wixf150 验证数字:^[0-9]*$ 验证n ...
- 理清JavaScript正则表达式--上篇
在JavaScript中,正则表达式由RegExp对象表示.RegExp对象呢,又可以通过直接量和构造函数RegExp两种方式创建,分别如下: //直接量 var re = /pattern/[g | ...
- 理清JavaScript正则表达式--下篇
紧接:"理清JavaScript正则表达式--上篇". 正则在String类中的应用 类String支持四种利用正则表达式的方法.分别是search.replace.match和s ...
- Test Regular Expressions Online with RegExr免费的正则表达式检验网站
免费的正则表达式检验网站: http://www.regexr.com
- JavaScript正则表达式详解(一)正则表达式入门
JavaScript正则表达式是很多JavaScript开发人员比较头疼的事情,也很多人不愿意学习,只是必要的时候上网查一下就可以啦~本文中详细的把JavaScript正则表达式的用法进行了列表,希望 ...
随机推荐
- Linux 下挂在ntfs 硬盘
CentOS 7 下想要挂载NTFS的文件系统该怎么办呢? 我们需要一个NTFS-3G工具,并编译它之后在mount就可以了,就这么简单. 首先要进入官网下载NTFS-3G工具 http://www. ...
- Grafana中整个Dashboard报错问题解决
操作Grafana时,有时不小心按了"CTRL+Z",会导致整个Dashboard出错,如下所示: 目前找到一个解决方案,也许不是正路,但是能解决上述问题,如果有了更简单有效的解决 ...
- js模块化/js模块加载器/js模块打包器
之前对这几个概念一直记得很模糊,也无法用自己的语言表达出来,今天看了大神的文章,尝试根据自己的理解总结一下,算是一篇读后感. 大神的文章:http://www.css88.com/archives/7 ...
- Hadoop生态系统图解
Hadoop生态架构图 参考文章: Hadoop生态系统介绍 HDFS架构 1.NaneDode:主节点,**存储文件的元数据**如文件名,文件目录结构,文件属性(生成时间,副本数量,文件权限),以及 ...
- Unrooted Tests错误
使用Junit4做测试,遇到如下问题: 条件如下: Eclipse里的Maven工程. 使用JUnit4(这个是否必须不知,反正我的工程用的4) 修改某个Test类里的方法名,或者增加一个Test方法 ...
- CJOJ 2482 【POI2000】促销活动
CJOJ 2482 [POI2000]促销活动(STL优先队列,大根堆,小根堆) Description 促销活动遵守以下规则: 一个消费者 -- 想参加促销活动的消费者,在账单下记下他自己所付的费用 ...
- solr6.3 + Hbase Indexer使用MR创建索引,错误Bad return type
使用solr6.3 + Hbase Indexer ,通过Hbase-indexer从Hbase建立索引到solr中,进行全文搜索. 两种实现方式:① 开启hbase-indexer进行实时同步新数据 ...
- AllPairs运用遇到的问题及解决办法分享
前些天用AllPairs自动生成了交互式测试用例,中间遇到的问题困扰了一天,最后解决了.现在分享下解决过程 首先,D\AllPairs是我的ALLPairs安装目录,C盘桌面test.txt是我写的测 ...
- bzoj2038: [2009国家集训队]小Z的袜子(hose) [莫队]
Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……具体来说,小Z把这N只袜 ...
- 手机摄像头扫描识别车牌号,移动端车牌识别sdk
一.移动端车牌识别应用背景 (技术交流:18701686857 QQ:283870550) 随着经济水平的不断提高,汽车数量的不断激增为汽车管理带来了不小的难度.路边违章停车的现象越来越频繁.现在, ...