Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:40:39+00:00 2026-05-20T04:40:39+00:00

I have a function that performs a Luhn check on a card entry when

  • 0

I have a function that performs a Luhn check on a card entry when a form is posted.

<script language="javascript">
 function Calculate(Luhn)
{
var sum = 0;
for (i=0; i<Luhn.length; i++ )
{
    sum += parseInt(Luhn.substring(i,i+1));
}
var delta = new Array (0,1,2,3,4,-4,-3,-2,-1,0);
for (i=Luhn.length-1; i>=0; i-=2 )
{       
    var deltaIndex = parseInt(Luhn.substring(i,i+1));
    var deltaValue = delta[deltaIndex]; 
    sum += deltaValue;
}   
var mod10 = sum % 10;
mod10 = 10 - mod10; 
if (mod10==10)
{       
    mod10=0;
}
return mod10;
}

function Validate(Luhn)
{
var LuhnDigit = parseInt(Luhn.substring(Luhn.length-1,Luhn.length));
var LuhnLess = Luhn.substring(0,Luhn.length-1);
if (Calculate(LuhnLess)==parseInt(LuhnDigit))
{
    return true;
}
alert("\n\nYou have mis-typed your card number! \nPlease check and correct.\n\n")   
return false;
}

I also have a function that removes any spaces that may have been entered in the card number onblur.

function stripChar(sValue, sChar) {
var i, tempChar, buildString;
buildString = ""
for (var i=0; i<sValue.length; i++) {
    tempChar = sValue.charAt(i);
    if (tempChar != sChar) {
        buildString = buildString + tempChar;
    }
}
return buildString;

How do I combine the functions so that the spaces are removed and the card number checked onblur.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:40:39+00:00Added an answer on May 20, 2026 at 4:40 am

    In your onblur function you could use:

    Validate(stripChar(sValue, sChar));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript function that accepts a number and performs a mathematical operation
I have a function that performs a hierarchical clustering on a list of input
I have a .click() function that performs certain actions when a button is clicked.
I have a jQuery function that performs slideDown anitmation on a certain element when
I have a function that takes a pointer to a superclass and performs operations
To cut a long story short I have a C# function that performs a
Suppose I have a function that performs some task (this is in Python pseudocode):
I have a script that performs some simple editing which works fine, the problem
If I have a function that performs some procedure and then needs to return
I have a function that performs a very expensive computational task on a click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.