How do I check a regular expression that sometimes has white space in the middle, and sometimes doesn't? For example, how can I validate a credit card number based on just length, actual content doesn't matter.
Currently I'm doing
var pattern = /^\s*\d{4} \d{4} \d{4} \d{4}\s*$/;
var result = pattern.test(CC);
if (result) {/* do thing */
This returns true if the number looks like XXXX XXXX XXXX XXXX. It however, keeps return true if I do more XXXX's, so "XXXX XXXX XXXX XXXX XXXX" is still returning true. I also need to figure out how to make XXXXXXXXXXXXXXXX return true as well.
I also have another conundrum, this one may be simpler.
{
if(myAge >= 0 && myAge <= 118)
{
HTML.innerHTML = "";
}
else
HTML.innerHTML = "Invalid age";
}
If you set the input to myAge = 0 in the input box, and then back space so there is no number, it keeps returning true, is there a way to assert that when the box is empty that it will return to false???
Any help on any of the problems would be much appreciated, thank you!