1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
o-na [289]
4 years ago
5

You have been asked to write a username validation program for a small website. The website has specific rules on what constitut

es a valid username, including:
All usernames must be between 8 and 15 characters long

Usernames can only contain alphabetic (a-z and A-Z) and numeric characters (0-9) - no special characters are allowed.

The first character in a username cannot be a digit

Usernames must contain at least one uppercase character

Usernames must contain at least one lowercase character

Usernames must contain at least one numeric character

Write a program that asks the user to enter in a username and then examines that username to make sure it complies with the rules above. Here's a sample running of the program - note that you want to keep prompting the user until they supply you with a valid username:

Please enter a username: foo
Username must be between 8 and 15 characters.

Please enter a username: fooooooooooooooooooo
Username must be between 8 and 15 characters.

Please enter a username: foo ooo ooo
Username must contain only alphanumeric characters.

Please enter a username: foooooooooo
Your username must contain at least one digit

Please enter a username: 1fooooooooo
The first character in your username cannot be a digit

Please enter a username: fooooooooo1
Your username must contain at least one uppercase character

Please enter a username: Fooooooooo1
Your username is valid!
Computers and Technology
1 answer:
vazorg [7]4 years ago
5 0

Answer:

var username;           // username entered by user

var charAny;            // text character identified in username

var anyNum = false;     // digit variable used to detect whether the username has one or not

var index;              // index loop variable

var BR = "<br />";      //break

var ES = "";            //space

// Display program requirements for the username requested

document.write("We'll begin helping you select a username" + BR);

document.write("Your username must have at least 8 characters," + BR);

document.write("   start with a letter, and contain at least 1 numeric character." + BR);

username = prompt("Please enter your username: ", ES);

// Check for length of username

while (username.length < 8) {

   document.write("Your username must be at least 8 characters long." + BR);

   username = prompt("Please enter your username: ", ES);

}

// Check that first character is a letter

// Substring function has three arguments: string, starting position, and ending position

charAny = username.substr(0, 1);

while (charAny !== isLetter()) {

   document.write("The first character of your username must be a letter." + BR);

   username = prompt("Please enter your username: ", ES);

}

// Check that there's at least one digit in the username

while (anyNum !== false) {

// Check each character, set anyNum to true if a digit

   for (index = 1; index < username.substr(index, index); index++) {

       anyNum = username.substr(index, index);

       if (isNumeric(charAny)) {

           anyNum = true;

       }

   }

   // If anyNum is false there were no numerics

   if (anyNum !== true) {

       document.write("Your username must include at least 1 digit." + BR);

       username = prompt("Please enter your username: ", ES);

   }

}

You might be interested in
What feature of excel allows you to automatically calculate common formulas with selected data
Nostrana [21]
It would be autosum your welcome:)
7 0
4 years ago
A relational database has been created to store data about subjects that students are studying. The following is a
12345 [234]

Mention two charactarestics of money that make it a sustainable medium of exchange

7 0
3 years ago
Complete the following tasks. When you are finished, click Done to close the lab and move to the next question. After you click
DiKsa [7]

What would be the correct cable would be an DSL cord for the phonelines.

8 0
3 years ago
Which actions changed the look of the following word?
Julli [10]
We need to see the word to know what it looks like to answer your question.
3 0
3 years ago
Read 2 more answers
Alice just wrote a new app using Python. She tested her code and noticed some of her lines of code are out of order. Which princ
kaheart [24]

Answer:

Sequencing

Explanation:

I have taken the test

5 0
3 years ago
Other questions:
  • What is an example of asynchronous communication
    7·1 answer
  • Over a TCP connection, suppose host A sends two segments to host B, host B sends an acknowledgement for each segment, the first
    6·1 answer
  • What is responsible for coordinating a computer's hardware and software components?
    13·1 answer
  • Please, Help me with this question, I tried it but It always says #Value.
    5·1 answer
  • What to do when you accidentally delete usb drivers?
    8·1 answer
  • Mencione algunos ejemplos en donde sean utilizadas las máquinas de aire comprimido. Justifique su respuesta.
    7·1 answer
  • FRQ: Hotel Rooms Part A &amp; B Edhesive
    10·1 answer
  • How do cyber criminals target user’s end devices?
    11·2 answers
  • The price of an item you want to buy is given in dollars and cents. You pay for it in cash by giving the clerk d dollars and c c
    6·1 answer
  • Similarities of ROM and RAM?​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!