You develop a webpage by using HTML5. You create the following markup and code: (Line
numbers are included for reference only.)
You need to ensure that the values that users enter are only numbers, letters, and
underscores, regardless of the order.
Which code segment should you insert at line 04?
Option A
Option A
Option B
Option B
Option C
Option C
Option D
Option D
Correct Answer
A
Explanation Explanation: Example: Sometimes situations arise when user should fill a single or more than one fields with alphabet characters (A-Z or a-z) in a HTML form. You can write a JavaScript form validation script to check whether the required field(s) in the HTML form contains only letters. Javascript function to check for all letters in a field view plainprint? function allLetter(inputtxt) { var letters = /^[A-Za-z]+$/; if(inputtxt.value.match(letters)) { return true; } else { alert("message"); return false; } } To get a string contains only letters (both uppercase or lowercase) we use a regular expression (/^[A-Za-z]+$/) which allows only letters. Next the match() method of string object is used to match the said regular expression against the input value. Reference: JavaScript : HTML Form validation - checking for all letters
Question ID 14935
You develop an HTML5 web application. The web application contains a form that allows
users to enter only their month of birth.
The value that the users enter must be numbers between 1 and 12, inclusive.
You need to implement the form element for the month of birth.
Which element should you use?