什么是使用CSV上传的MM / DD / YYYY格式的正则表达式 [英] What is regex of MM/DD/YYYY formate using CSV upload

查看:113
本文介绍了什么是使用CSV上传的MM / DD / YYYY格式的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static bool hasValidCharforDate(string input)

{

Regex r = new Regex(^(0 [1-9] | [12] [0- 9] | 3 [01])[ - /.](0[1-9]|1[012])[- /。](19| 20)\\\\\\。 ;



if(r.IsMatch(输入))

{

返回false;

}



返回true;

}



< b>我尝试了什么:



请帮帮我



i我试图验证日期和我需要mm / dd / yyyy格式,所以请给我正则表达式代码

解决方案

。);



if(r.IsMatch(输入))

{

返回false;

}



返回true;

}



我的尝试:



请帮帮我



i我试图验证日期,我需要mm / dd / yyyy格式所以请给我正则表达式代码


不要使用正则表达式验证日期,使用DateTime.TryParseExact。



 DateTime dt; 
string dateText =01/30/2018;
bool valid = DateTime.TryParseExact(dateText,MM / dd / yyyy,System.Globalization.CultureInfo.CurrentCulture,System.Globalization.DateTimeStyles.None,out dt);


public static bool hasValidCharforDate(string input)
{
Regex r = new Regex("^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d$.");

if (r.IsMatch(input))
{
return false;
}

return true;
}

What I have tried:

Please help me

i am trying to validate date and i need in mm/dd/yyyy format so please give me regex code

解决方案

.");

if (r.IsMatch(input))
{
return false;
}

return true;
}

What I have tried:

Please help me

i am trying to validate date and i need in mm/dd/yyyy format so please give me regex code


Don't use regex to validate dates, use DateTime.TryParseExact.

DateTime dt;
string dateText = "01/30/2018";
bool valid = DateTime.TryParseExact(dateText, "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt);


这篇关于什么是使用CSV上传的MM / DD / YYYY格式的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆