Last active
July 22, 2017 14:04
-
-
Save karthikbgl/f98cc3778234dc4fcbb33cfac4d57a8f to your computer and use it in GitHub Desktop.
Regex pattern matches using jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.regexFinder = function(text) { | |
/* | |
Phone number formats | |
XXX-XXX-XXXX | |
XXX.XXX.XXXX | |
XXX XXX XXXX | |
*/ | |
var cc_re = /(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][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})/g; | |
var date_re = /\d{2}\/\d{4}/g; | |
var email_re = /(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g; | |
var phone_re = /\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/g; | |
var ssn_re = /(\d{3}-?\d{2}-?\d{4})/g; | |
var zipcode_re = /\d{5}(-\d{4})?/g; | |
text = text.replace(cc_re, '<Masked CC Number>') | |
text = text.replace(email_re, '<Masked Email>'); | |
text = text.replace(phone_re, '<Masked Phone #>'); | |
text = text.replace(zipcode_re, '<Masked Zipcode>'); | |
text = text.replace(ssn_re, '<Masked SSN>'); | |
text = text.replace(date_re, '<Masked MM/YYYY>'); | |
return text; | |
}; | |
}(jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(function(){ | |
$("textarea").focusout(function() { | |
var val = $(this).regexFinder($(this).val()); | |
$(this).val(val); | |
}); | |
}); | |
</script> | |
<textarea rows=20 cols=60> | |
ABCD karthikb@gadmfs.com | |
AbC karthik@fads.com fdasfsadf | |
404-626-6115 abc1234046266115 | |
def 111-11-1111 and 112121234 | |
Zip: 10013 | |
Zip: 10013-0500 | |
11/2015 | |
12/11/2016 | |
Visa #: 4111111111111111 | |
MC #: 5105105105105100 | |
AMEX #: 30569309025904 | |
JCB #: 3530111333300000 | |
</textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment