-
javascript下调用正则表达式的方法
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
function checkByRegExp(regular, value)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
3
if (_isIe)
4![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
5
var re = new RegExp(regular);
6
if (value.match(regular) == null)
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
8
return false;
9
}
10
return true;
11
}
12
else
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
var re = new RegExp(regular);
15
if (!re.exec(value))
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
17
return false;
18
}
19
return true;
20
}
21
}
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
或是
24![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function regcheck(el, reg, msg)
{ //正则表达式验证
25
var val = el.value;
26![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!val || !reg.test(val))
{
27
alert(msg);
28
el.focus();
29
return false;
30
}
31
return true;
32
}
33![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function checknull(el,msg)
{ //非空验证
35![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!el.value)
{
36
alert(msg);
37
el.focus();
38
return false;
39
}
40
return true;
41
}
-
相关阅读:
转转帖.NET.GC 浅谈.net托管程序中的资源释放问题 (转帖)
[转]来谈谈从专业到更专业
[转]ASP.NET中多国语言的实现
[转]内向的人如何建立人际网络
SQL 入门 (代码)
SQL 查询 (代码)
关于学生信息处理小代码
SQL 函数 (代码)
SQL 链接 (代码)
SQL 数据表的相关操作
-
原文地址:https://www.cnblogs.com/litsword/p/1459140.html
Copyright © 2020-2023
润新知