javascript 常用验证正则表达试

 switch (type) {
                    case "empty":
                        result = writeMsg(id, msg, (val == ''));
                        break;
                    case "number":
                        //result = writeMsg(id, msg, (isNaN(val)));/*是否是数字*/
                        var patrn = /^[0-9]+$/;
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "double":
                        var patrn = /^[0-9.]+$/;
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "date":
                        var patrn = /^(d{1,4})(-|/)(d{1,2})2(d{1,2})$/;/*YYYY-MM-DD*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "time":
                        var patrn = /^((20|21|22|23|[0-1]d):[0-5][0-9])(:[0-5][0-9])?$/;/*hh:mm:ss*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "datetime":
                        var patrn = /^(d{1,4})(-|/)(d{1,2})2(d{1,2}) (d{1,2}):(d{1,2}):(d{1,2})$/;/*YYYY-MM-DD hh:mm:ss*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "url":
                        var patrn = /^http(s)?://([w-]+.)+[w-]+(/[w- ./?%&=]*)?$/;/*网址*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "email":
                        var patrn = /^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/;/*邮件*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "identity":
                        var patrn = /^d{17}[d|X]|d{15}$/;/*身份证号*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "ip":
                        var patrn = /^(((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5])).){3}((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5]))$/;
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "zip":
                        var patrn = /^d{6}$/;/*邮编*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "qq":
                        var patrn = /^[1-9][0-9]{4,}$/;
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "phone":
                        var patrn = /^d{3}-d{8}|d{4}-d{7,8}|d{11}|d{12}$/;/*电话*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "mobile":
                        var patrn = /^(13|15|18)d{9}$/;/*手机*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "string":
                        var patrn = /^[a-zA-Z0-9_]+$/;/*a-z,A-Z,0-9 */
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "image":
                        var patrn = /(.jpg|.gif|.bmp|.png|.img|.swf)$/;/*图片扩展名*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "html":
                        var patrn = /(.htm|.html|.shtml)$/;
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "chinese":
                        var patrn = /^[u0391-uFFE5]+$/;/*中文*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                    case "userorpwd":
                        var patrn = /^[A-Za-z0-9]{6,20}$/;/*6-20位;只限数字(0-9)和英文(a-z),不区分大小写*/
                        result = writeMsg(id, msg, (regular(val, patrn)));
                        break;
                }

时间: 2024-10-29 18:11:53

javascript 常用验证正则表达试的相关文章

常用的正则表达试

   public function funcStr($str,$num1='',$num2='') //字符正则表达试  {   if($num1!='' and $num2!=''){    return (preg_match("/^[a-zA-Z]{".$num1.",".$num2."}$/",$str))?true:false;   }else{    return (preg_match("/^[a-zA-Z]/"

php 手机号码正则表达试程序代码

代码如下 function funcMtel($str)//手机号码正则表达试 { return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true:false; } 测试 18678785887 返回为 false 原因分析,查看了发现上面正则只能验证以13,15开头的,自然18开头的是不可以用的 修改后 代码如下 function funcMtel($str)//手机号码正则表达试 { return (preg_match(&

JavaScript常用验证函数实例汇总_javascript技巧

本文实例汇总了JavaScript常用验证函数.分享给大家供大家参考.具体汇总如下: 一.字符串类验证 1. 长度限制 复制代码 代码如下: <script> function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符!"); document.a.b.focus(); return false; } } </script> <form name=a onsubmit=&

php url正则表达试

 代码如下 复制代码 function funcurl($str)//url正则表达试  {   return (preg_match("/^http://[a-za-z0-9]+.[a-za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/",$str))?true:false;  } 

javascript 常用验证函数总结_javascript技巧

/** * 2010-7-13 * 贺 臣 * 情 缘 * js各种表单数据验证 */ /**************************************************************************************/ /*************************************数字的验证*****************************************/ /******************************

javascript身份证验证正则与详细说明

网页特效身份证验证正则与详细说明 1.简单的正则表达式: (1)preg_match("/^(d{18,18}|d{15,15}|d{17,17}x)$/",$id_card) (2)preg_match("/^(d{6})(18|19|20)?(d{2})([01]d)([0123]d)(d{3})(d|x)?$/",$id_card) (3)preg_match("/(^d{15}$/)|(d{17}(?:d|x|x)$/),$id_card) 2.复

一个常用的正则表达验证类

 很早以前写的一个正则表达式验证工具类,包含了一些常见的校验和支持自定义的正则表达式匹配,可以选择完全匹配,也可以获取所有匹配项.曾用它仿造Eclispe下的正则表达式插件写过一个工具.因为最近突然有几个朋友都在问这方面的问题,干脆就把代码贴出来好了. using System; 02.using System.Collections; 03.using System.Text.RegularExpressions; 04. 05.namespace Xrinehart.Framework.Co

网页开发中常用javascript注册验证正则

 是否为数字.字母或下划线*/       function isnlu(ui){          var valid=/^w+$/;       return(valid.test(ui))    }       /*删除字符串中空格*/       user_pwd.replace(/s+/g,"");       /*    是否为邮箱地址    */       if((user_mail.indexof("@")<0)||(user_mail.in

javascript 常用验证函数

javascript|函数 一.验证类1.数字验证内  1.1 整数  1.2 大于0的整数 (用于传来的ID的验证)  1.3 负整数的验证  1.4 整数不能大于iMax  1.5 整数不能小于iMin2.时间类  2.1 短时间,形如 (13:04:06)  2.2 短日期,形如 (2003-12-05)  2.3 长时间,形如 (2003-12-05 13:04:06)  2.4 只有年和月.形如(2003-05,或者2003-5)  2.5 只有小时和分钟,形如(12:03)3.表单类