zoukankan
html css js c++ java
正则表达式 验证 ****年**月
因为要验证的字符串中 需要包含固定的相关中文汉字
所以 要先取得这些汉字的ASCII码表示
然后才能利用这些 构建验证规则
示例如下
/**/
/*
--------------------------------------------------
* 函數名稱: GetReportDate
* 目 的: 得到符合报表要求的相关日期
* 參 數:
* strDate :日期字符串
* reportDateType:可选值 Month ,HalfMonth ,
*
* Eg: GetReportDate("2006年12月","Month") = 20061216
* GetReportDate("2006年12月上半月","HalfMonth") = 20061201
* xx. YYYY/MM/DD VER AUTHOR COMMENTS
* 1. 2006/12/13 1.00 Free Create
------------------------------------------------------
*/
function
GetReportDate(strDate,reportDateType)
{
var
paraDateType
=
reportDateType.trim().toLowerCase();
//
判断 reportDateType 是否输入正确
var
TypeEnum
=
"
month,halfmonth
"
;
if
( TypeEnum.indexOf(paraDateType)
==
-
1
)
return
false
;
//
判断 strDate 的格式 是否与reportDateType相匹配
var
paraDate
=
strDate.trim();
var
regStr,regResult;
var
strLength
=
paraDate.length;
//
对于 Month 类的输入日期
if
(paraDateType
==
"
month
"
)
{
//
var yearASCII = escape("年");//得到 “年” 的ASCII码 \u5E74
//
var monthASCII = escape("月"); ////得到 “月” 的ASCII码 \u6708
regStr
=
/
\d
{
4
}
(\u5E74)\d
{
1
,
2
}
(\u6708)
/
;
}
regResult
=
regStr.test(paraDate);
if
(
!
regResult )
return
;
//
进行相关转换
var
returnDate ,tmpYear,tmpMonth,tmpDay;
//
Month 类的输入日期
if
(paraDateType
==
"
month
"
)
{
tmpYear
=
paraDate.substr(
0
,
4
);
tmpMonth
=
paraDate.substr(
5
,strLength
-
6
);
if
(tmpMonth
>
12
||
tmpMonth
<
1
)
{
return
;
}
else
{
if
(tmpMonth.length
==
1
)
{
tmpMonth
=
"
0
"
+
tmpMonth;
}
}
//
当月的16号
returnDate
=
tmpYear
+
tmpMonth
+
"
16
"
;
}
//
返回结果
return
returnDate;
}
查看全文
相关阅读:
叶树:任总喊你回家吃饭 (zz)
一个小员工如何让一家大银行一夕倒闭(附几则)
精妙SQL语句收集
降温了 降温了
東京タワー初めてphoto
圣诞气氛photo
初冬071110photo
超级郁闷的一天
eveningplan
KOF怀念ING
原文地址:https://www.cnblogs.com/freeliver54/p/591971.html
最新文章
could not open parameter file initOraceSID.ora
Chapter20Using Globalization Support
tnsnames.ora
Chapter02Oracle Net Architecture
远程安装Oracle Server
Linux常用命令
Oracle 用户管理
Chapter01Netwoking Overview
PAT 1060 Are They Equal[难][科学记数法]
知识点1树状数组[带poj Stars作为巩固]
热门文章
PAT 1090 Highest Price in Supply Chain[较简单]
PAT 1057 Stack [难][树状数组]
uva The Tower of Babylon[LIS][dp]
PAT Sum of Number Segments[数学问题][一般]
PAT 1079 Total Sales of Supply Chain[比较]
PAT 1109 Group Photo[仿真][难]
知识点2对二进制的运用
PAT 1094 The Largest Generation[bfs][一般]
wix 操作 ini 文本 文件
The Road Not Taken (zz)
Copyright © 2011-2022 走看看