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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

credit card parsing - Can anyone share a method/routine?

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I am struggling with this - I thought it would be very simple.

I guess that my not knowing preg_match does not help

I found this:
but it does not work; my guess is that this is due to credit cards having changed their encoding !?!

jquery.payment.js is not working either ... besides, I am not sure I want to use jquery for this task!

Thanks you all in advance.


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Too often I post a question here looking for help just to find a solution or plug shortly there after.

Mind you, I spend a great deal of time working on my problem before I come here seeking for help, it is how one learns, by struggling. Since I ask the question and then find what may be an answer, I also like to post what I came up with so, here it is:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var	setCreditCardAttributes = function(string){
        try {
		    string = string.replace('%B', '');
            string = string.replace('%b', '');
            
            var arr = string.split('^');
            var nameArr = arr[1].split(' ');
            var len = nameArr.length;
            
            this.creditcardnumber = arr[0];
			document.getElementById('number').value=this.creditcardnumber;

            this.month = arr[2].substring(2, 4);
            this.year = arr[2].substring(0, 2);
			document.getElementById('expires').value=arr[2].substring(2, 4)+"/"+arr[2].substring(0, 2);

            this.first_name = '';
            this.last_name = '';
			
			nameArr = arr[1].split('/');
            this.first_name = nameArr[1];
			document.getElementById('fname').value=nameArr[1];
            this.last_name = nameArr[0];
			document.getElementById('lname').value=nameArr[0];
			this.payment_method_id=1;
			this.type='credit';

	    } 
        catch (err) {
            pushToErrorLog('class Payment::setCreditCardAttributes() ' + err);
            displayMessageWindow('Error With Card', 'There was an error reading the data from this card', 'error');
        }
	}

function returnKey(evt)
{
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
 
	if ((evt.keyCode == 13) && (node.type == "text")) 
	{
		switch(node.id)
		{
			case 'p1cc':
				setCreditCardAttributes(document.getElementById('p1cc').value); break;
 
		}
	}
}

 	
document.onkeypress = returnKey;

</script>
</head>

<body>
<input name="p1cc" id="p1cc" type="text" size="55" maxlength="256" />

<input id="fname" type="text" />
<input id="lname" type="text" />
<input id="expires" type="text" />
<input id="number" type="text" />

</body>
</html>



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top