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 8879805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:02:00+00:00 2026-06-14T20:02:00+00:00

I’m building a basic credit card validator in Codeigniter, here is my HTML: <input

  • 0

I’m building a basic credit card validator in Codeigniter, here is my HTML:

<input type="text" id="ccard" />
<input type="submit" onClick="check_cc()" name="submit_cc" value="Validar cartão!" id="checkcc" />
<div id="result"></div>

The JavaScript function:

function check_cc() {
    var cc;
    cc = $("#ccard").val();

    $.ajax({
        url: '<?php echo base_url() . "js_tests/check_cc_string"; ?>',
        type: 'POST',
        data: {credit_card : cc},
        success: function(output_string) {
            setTimeout(function() {
                $('#result').append(output_string);
            }, 1000);
        }
    });
}

(at this point I’m not entirely sure if what I’m doing with the URL is actually right. The function seems to trigger on the controller, but not sure if the cc variable is being passed)

This is my controller:

function check_cc_string() {
    $check = check_cc($_POST['cc'], true);
    if ($check !== false) {
        $output_string = $_POST['cc'] . " - " . $check;
    } else {
        $output_string = " - Not a match";
    }

    echo json_encode($output_string);
}

Also inside the controller, the credit card checker:

function check_cc($cc, $extra_check = false) {
    $cards = array(
        "visa" => "(4\d{12}(?:\d{3})?)",
        "amex" => "(3[47]\d{13})",
        "jcb" => "(35[2-8][89]\d\d\d{10})",
        "maestro" => "((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)",
        "solo" => "((?:6334|6767)\d{12}(?:\d\d)?\d?)",
        "mastercard" => "(5[1-5]\d{14})",
        "switch" => "(?:(?:(?:4903|4905|4911|4936|6333|6759)\d{12})|(?:(?:564182|633110)\d{10})(\d\d)?\d?)",
    );
    $names = array("Visa", "American Express", "JCB", "Maestro", "Solo", "Mastercard", "Switch");
    $matches = array();
    $pattern = "#^(?:" . implode("|", $cards) . ")$#";
    $result = preg_match($pattern, str_replace(" ", "", $cc), $matches);
    if ($extra_check && $result > 0) {
        $result = (validatecard($cc)) ? 1 : 0;
    }
    return ($result > 0) ? $names[sizeof($matches) - 2] : false;
}

Unfortunately, this is returning me this:

Fatal error: Call to undefined function check_cc()

I’m not an expert in these things, but am I right to believe the url passed on jQuery is accessing that PHP function directly? Thus not being able to read the rest of the file?

Is there a practical way to go over this or will I have to rebuild my function to include all of the credit card validation code?

  • 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-06-14T20:02:01+00:00Added an answer on June 14, 2026 at 8:02 pm

    You are trying to access the $cc as a parameter in check_cc_string function.
    The $.ajax sends an httprequest to the controller, and the data is passed via $_POST, by default.
    When calling the check_cc you should use $this->

    Try This:

    function check_cc_string() {
        $c = $_POST['cc'];
        $check = $this->check_cc($c, true);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.