Answer to Question #63155 in AJAX | JavaScript | HTML | PHP for Miguel Rivera

Question #63155
Write a function that takes in one argument. The function should return true if the passed in argument is a valid X Number. A valid X number is 9 characters in length, begins with a X and ends with 8 digits. The function should return false if it is not valid X Number.
Call the function 4 times, 2 times with valid X Numbers and 2 times with invalid X Numbers and display the results.
1
Expert's answer
2016-11-10T13:42:09-0500
function checkNumber(n) {
return n.match(/^X\d{8}/)?true:false;
}

console.log(checkNumber('X00878765'));
console.log(checkNumber('X28878765'));
console.log(checkNumber('X2887876'));
console.log(checkNumber('32887876'));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS