正则表达式 验证 ****年**月
来源:互联网 发布:淘宝虚拟试衣功能在哪 编辑:程序博客网 时间:2024/05/01 05:20
因为要验证的字符串中 需要包含固定的相关中文汉字
所以 要先取得这些汉字的ASCII码表示
然后才能利用这些 构建验证规则
示例如下
所以 要先取得这些汉字的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;
}
* 函數名稱: 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;
}
- 正则表达式 验证 ****年**月
- js 日期正则表达式支持月日验证
- 正则表达式验证验证
- 正则表达式,验证框验证
- 身份证号验证正则表达式
- Email验证正则表达式
- 日期验证正则表达式
- 正则表达式验证
- 验证电话号码正则表达式
- 时间验证(正则表达式)
- 正则表达式验证
- 正则表达式验证
- 正则表达式验证
- 正则表达式验证
- 正则表达式验证日期
- 10.5 正则表达式验证
- 正则表达式验证
- 正则表达式的验证
- SQL 2005 Express 的“企业管理器” 下载
- VS2005 安装项目 需要学习
- [引用]SQL Server 2005 Books Online How to: Create a Job with Steps and a Schedule in Visual Basic .NET
- VS2005 通过SMO(SQL Management Objects) 管理 数据库的作业 警报 备份 等任务
- 自定义控件的 Enum类和Color类 属性的公开设定
- 正则表达式 验证 ****年**月
- VS2005 XML注释生成XML文档文件
- 浏览器兼容
- 得到内网可用的SqlServer 及某数据库下的表及其他的架构
- Duwamish示例下载
- 华表 单元格公式设定与计算
- 设置VS团队开发 统一的编码方式为:签名的UTF-8
- Tomcat Web.xml写法
- 自定义控件开发示例二