C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






RegEx for credit card validation


Posted Date: 09 May 2008    Resource Type: Code Snippets    Category: Validations
Author: narasimhaMember Level: Gold    
Rating: Points: 10



This code sample shows how to use regular expressions to validate credit card numbers.

//Namespace Reference
using System.Text.RegulsrExpressions

///
/// method to validate a credit card number
///

/// cc number to validate
/// true/false
public static bool validCCNum(string num)
{
// This expression is looking for a series of numbers, which follow the pattern
// for Visa, MC, Discover and American Express. It also allows for dashes between sets of numbers
string pattern = @"^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$";
Regex match = new Regex(pattern);
return match.IsMatch(num);
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Allows one or more alphabetical and/or numeric characters. This is a more generic validation functi
Previous Resource: Javascript for Validations and Email check
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use