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
polet [3.4K]
3 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:

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

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

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

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

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

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

g.Please enter a username: Fooooooooo1
Your username is valid!

Computers and Technology
1 answer:
umka21 [38]3 years ago
3 0

Answer:

#function to validate username

def valid_username(username):

   

   #checking is length is between 8 to 15

   length_valid=True

   if(len(username)<8 or len(username)>15):

       length_valid=False;

   

   #checking is string is alphanumeric

   alphanumeric=username.isalnum()

   

   #checking first_and_last Characters of string is not digit

   first_and_last=True

   if(username[0].isdigit() or username[len(username)-1].isdigit()):

       first_and_last=False

   

   #counting uppercase lowercase and numeric Characters in string

   uppercase=0

   lowercase=0

   numeric=0

   

   for i in username:

       if(i.isdigit()):

           numeric=numeric+1

       elif(i.isalpha()):

           if(i.isupper()):

               uppercase=uppercase+1

           else:

               lowercase=lowercase+1

               

   valid_no_char=True

   if(uppercase<1 or lowercase<1 or numeric<1):

       valid_no_char=False

           

 

   #printing the result

   print("Length of username: "+str(len(username)))

   print("All Characters are alpha-numeric: "+str(alphanumeric))

   print("First and last Character are not digit: "+str(first_and_last))

   print("no of uppercase characters in the username: "+str(uppercase))

   print("no of lowercase characters in the username: "+str(lowercase))

   print("no of digits in the username: "+str(numeric))

   

   #checking string is Valid or not

   if(length_valid and alphanumeric and first_and_last and valid_no_char):

       print("Username is Valid\n")

       return True

   else:

       print("username is invalid, please try again\n")

       return False

#loop runs until valid_username enterd by user

while(True):

   

   username=input("Enter a username: ")

   if(valid_username(username)):

       break

Explanation:

The code was created by considering all the required cases asked in the question.

In this program, I asked username from the user continuously until it enters a valid username

first it check for length of string

then check is string contains only alphanumeric characters

then first and last digit is or not

than no of uppercase lowercase and numeric character

using the above parameter declare username valid or not

You might be interested in
Trying to make the baseplate red and turn off can collide then the game waits 5 seconds and turns on can collide, making the bas
kenny6666 [7]

Answer:

Explanation:

yes

but dont forget to call makeBasePlateGreen

maybe you would call it at the end of the program?

by the way you have a typo at the end

make the O lowercase

myBlasePlate.BrickColor = BrickColor.Green()

and then add this to the end

makeBasePlateGreen()

so you call the function and actually use it.

4 0
2 years ago
Which of the following is the best description of the [Drive for] block?
Ede4ka [16]
The answer is C to this question
6 0
2 years ago
A site has been issued the IP address of 192. 168. 10. 0/24. The largest network contained 25 hosts and was given the lowest num
dimulka [17.4K]

Answer:

Explanation: The first thing to calculate is what IP addresses are used by the largest LAN. Because the LAN has 100 hosts, 7 bits must be left for host bits.

Explanation:

Explanation: The first thing to calculate is what IP addresses are used by the largest LAN. Because the LAN has 100 hosts, 7 bits must be left for host bits.

4 0
1 year ago
Find the maximum value and minimum value in below mention code. Assign the maximum value to maxMiles, and the minimum value to m
Kobotan [32]

Answer:

Code works perfectly

Explanation:

There is nothing wrong with your program as it runs perfectly and displays the expected results.

You may need to compile with another compiler if you're not getting the required results.

I've added the source code as an attachment (unedited)

Download java
3 0
2 years ago
Change the shape fill color to Dark Red. It is the first option in the Standard Colors section of the color palette.
maxonik [38]
Is this a question ?
3 0
3 years ago
Other questions:
  • Please explain external hashing, B-trees, and traversals. 3-5 sentences per
    8·1 answer
  • Which of the following journals is not aimed at the public as well as scientists?
    7·1 answer
  • What is a main cause of an aurora?
    8·1 answer
  • How are switches indirectly involved in ARP poisoning?
    6·1 answer
  • Which of the following tools enables a production mixer to sync audio and video?
    7·1 answer
  • Generally speaking, what is a “best practice"?
    13·1 answer
  • Which pickaxe in minecraft to use?
    14·1 answer
  • Write a program that produces an expense report for a trip to Lagos, Nigeria. Use the Internet to research the cost to travel to
    13·1 answer
  • How do people decide their ethical behavior
    13·2 answers
  • which one of the following will reach every element in the array a? 1. for(int i = 0; i &lt;= a.length; i++) 2. for(int i = 0; i
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!