Re-theme site
This commit is contained in:
@@ -2,35 +2,26 @@
|
||||
title: Luhn Algorithm
|
||||
description: Replication of the Luhn algorithm
|
||||
layout: default
|
||||
icon: credit_card
|
||||
icon: credit-card
|
||||
---
|
||||
|
||||
<link href="style.css" rel="stylesheet" type="text/css">
|
||||
<script src="script.js" type="text/javascript"></script>
|
||||
|
||||
# Validate Your Number
|
||||
<!-- input field (in a container so that unwanted overflow from :before & :after is hidden) -->
|
||||
<div class="mdc-text-field-container">
|
||||
<div class="mdc-text-field mdc-text-field--outlined" data-mdc-auto-init="MDCTextField">
|
||||
<input type="number" id="number-input-field" class="mdc-text-field__input">
|
||||
<label for="number-input-field" class="mdc-floating-label ">Number</label>
|
||||
<div class="mdc-notched-outline">
|
||||
<svg>
|
||||
<path class="mdc-notched-outline__path"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="mdc-notched-outline__idle"></div>
|
||||
</div>
|
||||
<!-- input field helper text -->
|
||||
<p class="mdc-text-field-helper-text" aria-hidden="true">
|
||||
Validate with the Luhn Algorithm
|
||||
</p>
|
||||
</div>
|
||||
<!-- button to submit & check number with Luhn algorithm -->
|
||||
<button class="validation_button mdc-button mdc-button--outlined" onclick="checkNumber()" data-mdc-auto-init="MDCRipple">
|
||||
<i class="material-icons mdc-button__icon">check_circle_outline</i>
|
||||
Check
|
||||
</button>
|
||||
<!-- displays evaluation of number by Luhn algorithm -->
|
||||
<p id="validation_message"></p>
|
||||
|
||||
<form onreset="$('#validation_message').html(null);">
|
||||
<div class="row gtr-uniform">
|
||||
<div class="col-6 col-12-xsmall">
|
||||
<input type="number" id="number-input-field" placeholder="Number" />
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<ul class="actions">
|
||||
<li><a href="javascript:checkNumber();" class="button primary icon fa-check-circle">Check</a></li>
|
||||
<li><input type="reset" value="Reset"/></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p id="validation_message"></p>
|
||||
@@ -1,13 +1,25 @@
|
||||
document.addEventListener("keyup", function(event) {
|
||||
// stop any code that may normally run when enter key pressed
|
||||
event.preventDefault();
|
||||
// if enter key is pressed, run Luhn algorithm
|
||||
if (event.keyCode === 13) {
|
||||
document.addEventListener("keydown", function(event) {
|
||||
if (event.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
var handled = false;
|
||||
if (event.key === "Enter") {
|
||||
checkNumber();
|
||||
handled = true;
|
||||
} else {
|
||||
// if number in input field is being edited, remove previous number evaluation message
|
||||
$("#validation_message").html(null);
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
// Suppress "double action" if event handled
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$("input[type='reset']").addEventListener("keydown", function(event) {
|
||||
$("#validation_message").html(null);
|
||||
});
|
||||
|
||||
// function for validating number entered with Luhn algorithm
|
||||
|
||||
Reference in New Issue
Block a user