* The pattern attribute specifies a regular expression that the <input> element’s value is checked against.

* The pattern attribute works with the following input types: text, search, url, tel, email, and password

QUESTION 134

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?

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Correct Answer: A

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. – See more at: http://www.w3resource.com/javascript/form/all-letters- field.php#sthash.5Db50Bdm.dpuf

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. Here is the complete web document.See more at: