Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression for credit card expiration date 1

Status
Not open for further replies.

tperri

Programmer
Apr 8, 2006
728
US
I've found some sample regexs for dates, but they dont work in my validator. Does an yone have one they could share that will work with my asp.net reg expression validator?

Thanks in advance,
T
 
like jbenson says, the best would be a compare validotr for dates. why would u want to use a RegEx???

Known is handfull, Unknown is worldfull
 
The credit cards I have do not have a day. I do not believe the compare validator will work. Here is a regex that will take month year the year can be 2 or 4 digits. it only goes to the year 2019 and that may be too far out. Most of my credit cards are reissued every 3 years.
This will give you something to go on.
Code:
Match MyRegex = Regex.Match(_input,@"^(((0[5-9])|(1[0-2]))\/(06|2006)|((0[1-9])|(1[0-2]))\/(((0[7-9])|(1[0-9]))|((200[7-9])|(201[0-9]))))$",RegexOptions.IgnoreCase); 
if (MyRegex.Success) 
{
	Console.WriteLine(_input);
}
else
{
	Console.WriteLine(_input + " Is not month year or is less than 05/2006");
}
test results
Enter string: 04/06
04/06 Is not month year or is less than 05/2006
Enter string: 04/2006
04/2006 Is not month year or is less than 05/2006
Enter string: 01/07
01/07
Enter string: 04/07
04/07
Enter string: 12/12
12/12
Enter string: 12/2012
12/2012
Enter string: 07/2019
07/2019
Enter string: 7/09
7/09 Is not month year or is less than 05/2006
Enter string: 07/09
07/09

Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top