SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


RegEx CC


RegEx CC

Author
Message
Laura_SqlNovice
Laura_SqlNovice
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1067 Visits: 501
Hi Guys,

What I need to do is find rows that may have credit card in the text. Here is the regular expression I am using, but this one ignores the ones with space or hyphens.

(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})

What I need to do is:
Find character string that may have CC#s and the CC# might have space, hyphen or no delimeters between the group of numbers. The regex should work with all major CCs. The CC#s will be somewhere in between the text not at the start.

For example: "blah blah... 4258-1234-5678-1234. Email sent blah blah..."

The RegEx should catch the above string as the string of numbers look likes Visa CC #.

Anyone who has such RegEx?

Thanks,
Laura
Sean Lange
Sean Lange
SSC Guru
SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)

Group: General Forum Members
Points: 100816 Visits: 18175
Now that you decided to go full on CLR for this you have a myriad of resources for your searches. I found this one which looks pretty good.

http://www.regular-expressions.info/creditcard.html

Here is another one:


string ccRegEx = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$";



A quick google/bing should reveal thousands of examples.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Laura_SqlNovice
Laura_SqlNovice
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1067 Visits: 501
Thanks Sean for the response. I tested many regExes I found in google, but I couldnt find the one which will work with a char string where it will have CC# somewhere in the string that has alphanumeric characters as well as special characters.
Orlando Colamatteo
Orlando Colamatteo
SSC Guru
SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)

Group: General Forum Members
Points: 69096 Visits: 14491
I am not in a place where I can test, but it seems like simply adding a .* before and after the regex that matches your CC# pattern would make it work for any string.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Sean Lange
Sean Lange
SSC Guru
SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)SSC Guru (100K reputation)

Group: General Forum Members
Points: 100816 Visits: 18175
I think we can do it like this. Basically we just use a word boundary and a simple replace. This will find any values with numbers between 13 and 16 characters. Unless you have other long numeric values you shouldn't get too many false positives.


string ccRegEx = @"\b\d{13,16}\b";
string SomeValue = "this contains possible CC Nums 1234-5689-9875-5621 or so it seems.";
SomeValue = "blah blah... 4258-1234-5678-1. Email sent blah blah...";
Regex r = new Regex(ccRegEx);
bool found = r.IsMatch(SomeValue.Replace("-", ""));



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search