How do I validate a credit card expiry date with Javascript?

And for the credit card expiration validation you can do like this.

var today, someday;
var exMonth=document.getElementById("exMonth");
var exYear=document.getElementById("exYear");
today = new Date();
someday = new Date();
someday.setFullYear(exYear, exMonth, 1);

if (someday < today) {
   alert("The expiry date is before today's date. Please select a valid expiry date");
   return false;
}

In the following code you have some deviations

var firstName=document.getElementById("firstName");
var lastName=document.getElementById("lastName");
var email=document.getElementById("email");
var postcode=document.getElementById("postcode");
var paymentType=document.getElementById("paymentType");
//here why did you use .value. Probably removing .value would fix your issue
var exMonth=document.getElementById("exMonth").value;
var exYear=document.getElementById("exYear").value;
var cardNumber=document.getElementById("cardNumber").value;

change the last three lines to something like this

var exMonth=document.getElementById("exMonth");
var exYear=document.getElementById("exYear");
var cardNumber=document.getElementById("cardNumber");

I found a problem with the previous answer. I'm posting here my tested solution.

The problem with the previous answers they are not considering the day. For solve it you must use the last day of the month. To find it in Javascript you can use setFullYear(year, month, day) where the day is zero.

Bonus: month in javascript is 0 - 11

But when you set a month you shouldn't use month - 1.

Ex: setFullYear(2020, 6, 0) // -> 31 Jun 2020.

const today = new Date();
const ed = new Date();
ed.setFullYear(year, month, 0);

if (ed < today) {
}