Question
Write a function named isValidPostalCode that returns true if a given Canadian postal code is valid, otherwise it returns false. A valid postal code is
Write a function named isValidPostalCode that returns true if a given Canadian postal code is valid, otherwise it returns false. A valid postal code is in the format of LDL DLD, here L means a letter (uppercase or lowercase) and D means a digit. A valid code may contain spaces at the beginning or at the ending, and may or may not contain a single space in the middle.Create another function named checkPostalCode that reads the postal code entered in the input textbox, and replaces all the spaces in the code by using the String's replace method in the following way: replace(" ", ""). You can also convert all the letters to uppercases by calling the toUpperCase() method.The function checkPostalCode then calls the function isValidPostalCode to check whether the code from the user is valid. If not, display an appropriate message in an alert box, else display the message "Thank you for entering the postal code.", and if the user did not enter a space in the middle, insert a space there and update the code in the input textbox.The function checkPostalCode is called when the button is clicked.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started