exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 3 question 34 discussion

Actual exam question from Microsoft's 70-480
Question #: 34
Topic #: 3
[All 70-480 Questions]

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
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️
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

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
alexivv
4 years, 5 months ago
I think C is also a good answer. A word character (\w) is a character from a-z, A-Z, 0-9, including the _ (underscore) character.
upvoted 2 times
[Removed]
4 years, 5 months ago
Actually it wouldn't work because it matches only one character, it needs a + in the regex in order to be correct.
upvoted 1 times
...
...
shade03
4 years, 6 months ago
Why is there an ! in the if? Doesnt that mean Not?
upvoted 1 times
northgaterebel
4 years, 5 months ago
Yeah that confused me too at first. But it works. If not match then replace text with Invalid. Answer seems correct.
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...