PrepAway - Latest Free Exam Questions & Answers

You need to prevent users from entering specific characters into the username field

You develop an HTML5 webpage. You have the following HTML markup:
<input type=”text” id=”username” />
You need to prevent users from entering specific characters into the username field.
What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Using the keyup event, add an anonymous function that returns true when a specific
character keycode value is determined.

B.
Using the change event, add an anonymous function that returns true when a specific
character keycode value is determined.

C.
Using the keydown event, add an anonymous function that returns false when a specific
character keycode value is determined.

D.
Using the change event, add an anonymous function that returns false when a specific
character keycode value is determined.

Explanation:

7 Comments on “You need to prevent users from entering specific characters into the username field

  1. stenly says:

    question says preventing, change event cannot prevent any char not being inserted via keyboard as is demonstrated in created example from Hawgie https://jsfiddle.net/66c9e1Lf/

    but nothing is mention about coping and pasting – good to point this use case but i dont think should be addressed in any answer

    C is correct




    1



    0

Leave a Reply