Times a billion cash can u blog that 34

From Missouri Academy Wiki
Revision as of 01:43, 20 January 2012 by MyroslavCamp9 (talk | contribs) (Created page with "thumb| Flag this photograph Credit card numbers have diverse formats depending on the credit card kind. To example, Visa, MasterCard plus Dis...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Flag this photograph

Credit card numbers have diverse formats depending on the credit card kind. To example, Visa, MasterCard plus Discover each format their card numbers in 4 groups of 4 digits separated by means of dashes. American Express formats hers card number in groups of four, six and 5 digits, respectively, separated by way of dashes. You can format a credit card quantity based on the type in JavaScript by using the JavaScript "sprintf" method.

Trouble: Moderately Challenging

1 Create a new HTML document in one editor or in Microsoft Notepad. Create a variety to capture the credit card kind and credit card number. Assign a name to each and every input element to easily reference them from JavaScript. For example, type:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitory//EN website">

<html xmlns= website">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Format Credit Card Number</title>

</brain>

<body>

Pick credit card type:

<form title="cc">

<pick name="ccType">

<option value="Visa">Visa</option>

<choice value="MasterCard">MasterCard</option>

<option value="American Express">American Express</choice>

</select>

Enter credit card number (no dashes):

<input kind="text" name="ccNumber" />

2 Allot the submit actions to any JavaScript function you will create to format the credit card number. For example, type:

3 Reserve some place with some

tag to display the formatted number. With illustration, type:

</form>

</physique>

<script type="text/javascript">

function formatcc()

var cc = website.ccNumber;

cc.replace(/\-/, "");

6 Determine the credit card type with using the "switch" statement. Format the credit card quantity by using the "sprintf" function and the "substr" method. Substitute exclusive error information for the formatted card number if the credit card type is not recognized. For illustration, type:

switch (ccType)

situation "Visa": case "MasterCard": event "Discover":

var formatted = sprintf("%04d-%04d-%04d-%04d", cc.substr(0,4), cc.substr(4,4), cc.substr(8,4), cc.substr(12,4));

break;

case "American Express":

var formatted = sprintf("%04d-%06d-%05d", cc.substring(0,3), cc.substr(3,6), cc.substr(9,5));

break;

default:

var foramtted = "Could not identify credit card kind!";. Cash Advances.

break;

7 Replace the space reserved with the
tag with the formatted credit card amount. With illustration, type:

document.getElementById("formatted").innerHTML = "The formatted amount yous " + formatted;


</script>

Related Searches

References

SANS: Using Snort to Detect Clear Word Credit Card Numbers Dive In JavaScript: JavaScript sprintf internet site: JavaScript Change Statement website: JavaScript substr() Technique

Comstock/Comstock/Getty Images