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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:00:43+00:00 2026-06-02T01:00:43+00:00

I have the following function where I’m using regex matching to check for proper

  • 0

I have the following function where I’m using regex matching to check for proper date format when a change event happens on the value in the input field.

My problem is that month, day, and year are returning as NaN and I’m not sure why. I’m parsing regex objects [1], [2], and [3] respectively with parseInt() so I’m not sure why they are returning as NaN.

validateDate: function(event) {

        var input = $(event.target);
        var enteredDate = input.val();

        input.destroyValidationMessage();

        var pattern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
        var result = pattern.test(enteredDate);

        if (result !== null) {
            var month = parseInt(result[1], 10);
            var day = parseInt(result[2], 10);
            var year = parseInt(result[3], 10);
        }
   }
  • 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-02T01:00:43+00:00Added an answer on June 2, 2026 at 1:00 am

    .test() [MDN] returns a boolean, i.e. true or false and only tells you whether the expression matches the input or not.

    Then, since if(result !== null) is always true for result being either true or false, the if statement block is executed.

    match[x] is the same as true[x] (or false[x]) and instead of throwing an error, it returns undefined. This is because JavaScript converts the primitive value to an object internally and accessing a non-existing property results in the return value undefined.

    Furthermore, parseInt(undefined, 10) returns NaN.


    You want to use .match() [MDN]:

    var result = enteredDate.match(pattern);
    

    A shorter way of converting a numerical string to a number is using the unary + operator:

    var month = +result[1];
    

    which gives you the same result here since the input string only contains digits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that I use to check a user login, at
I have the following function, which I would like to plot using ggplot: f(x)
I have the following function: public function updateCustomerInternetBanking($value, $column_to_go_by) { $sql = UPDATE customer
I have the following function to post to Facebook using the latest iOS Facebook
I have the following function to get the value in a textarea with the
I have the following function: - (NSString *)urlEncodedValue { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(
I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for(
I Have the following function. function ChangeDasPanel(controllerPath, postParams) { $.post(controllerPath, postParams, function(returnValue) { $('#DasSpace').hide(slide,
I have the following function sending an email twice (and I believe running if($result)
I have the following function that deletes the LaTeX command surrounding the current cursor

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.