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.

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

  1. d says:

    I don’t think that B is the right answer. In order to prevent from entering special characters,
    the function should return false when a special character is entered.
    And I’m also not sure if the change event is the most suitable for this job.




    0



    0
  2. Bilbo says:

    i don’t think the keydown event works like this. just think about if someone just pastes text into the textbox, it would not trigger. a changed event would, so the keydown would be handled there.




    0



    0
      1. Tom says:

        Since nobody replied: the change event doesn’t contain keycodes, so you would never be able to determine which keycodes were pressed unless you convert the value of the input back to keycodes, which is weird and unlogical.




        0



        0
  3. anii says:

    I’m so confused and still don’t know what the correct answer is…

    I would say C (keydown) just because it’s the only event that actually prevents users from entering specific characters into the input field. (copying and pasting aside)




    1



    0
  4. j man says:

    I think C is the right answer as well. Microsoft likes to be tricky with these so they try to catch you on the semantics. So in this question the key words are “entering specific characters”, it doesn’t specifically say pasting characters. So keydown is the MOST right answer.




    1



    0

Leave a Reply