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;
}
查看全文
相关阅读:
编译安装mysql5.7.9
配置阿里云作为yum 源
python 序列类型
python 数据类型之list
python 数据类型之数float
深度学习与中文短文本分析总结与梳理
相似度的算法(欧几里德距离和皮尔逊算法)
人工智能(Machine Learning)—— 机器学习
python设置redis过期时间
K-均值聚类(K-means)算法
原文地址:https://www.cnblogs.com/freeliver54/p/591971.html
最新文章
mybatis和ibatis控制台打印sql语句方法
Ubuntu14.04下安装Hadoop2.4.0 (单机模式)
登录Cloudera Manager时报错org.hibernate.exception.GenericJDBCException: Could not open connection
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
轻易不要直接修改文档
关于flume中的几个疑惑
SparkStreaming+Flume出现ERROR ReceiverTracker: Deregistered receiver for stream 0: Error starting receiver 0
2014年12月总结和2014年1月计划
Scala中的Implicit(隐式转换,隐式参数,隐式类)
如何后台执行脚本程序?
热门文章
【转】reduce端缓存数据过多出现FGC,导致reduce生成的数据无法写到hdfs
解析Cloudera Manager内部结构、功能包括配置文件、目录位置等
nGrinder性能测试平台搭建(LVS压力测试)
/var/lock/subsys作用
Linux系统启动过程分析
隐藏Nginx/Apache版本号的安全性与方法
mysql隔离级别的设置和检索
MySQL与unix时间问题
linux----用户与whoami
Redis 数据库的安装
Copyright © 2011-2022 走看看