Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete this in Java. Thanks 1) [10 points] Write a program that validates ente

ID: 3889778 • Letter: C

Question

Complete this in Java. Thanks

1) [10 points] Write a program that validates entered username, password, email address, and phone number (for example, 313-456-7890). Password must have at least one capital letter, one lowercase letter, one digit, one underscore character, and should contain at least 6 characters. Username might contain digits, letters (lowercase only), and underscore symbols, but no spaces in the name Note 1: You should use regular expressions for a validation. Note 2: To check if the password have at least one digit you can use "positive lookahead" statement: (-*[0-9]) Expected output Enter username: username 123 Enter password: 123-Wtyi Enter email address: ake.ematlwgmatl.com Enter phone number 111-333-4444 Valid username! Valid password Valid email address! Valid phone number!

Explanation / Answer

The python code will look something like this:-

import re

validUsername = False
validPassword = False
validEmail = False
validPhonenumber = False


username = input("Enter username ")
usernameP = re.compile(r'^[a-z0-9_]{3,}$')
usernameM = usernameP.search(username)
try:
    usernameM.group()
    validUsername = True
except:
    validUsername = False

pswd = input("Enter Password ")
pswdP = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*_)[A-Za-zd_]{6,}')
pswdM = pswdP.search(pswd)
try:
    pswdM.group()
    validPassword = True
except:
    validPassword = False


email = input("Enter Email ").strip()
print(email)
emailP = re.compile(r"^S+@S+(.com)$")
emailM = emailP.search(email)
# print(emailM)
try:
    emailM.group()
    validEmail = True
except:
    validEmail = False


phoneNumber = input("Enter your phone number ")
if len(phoneNumber) == 12:
    p = re.compile(r'ddd-ddd-dddd')
    m = p.search(phoneNumber)
    try:
        m.group()
        validPhonenumber = True
        # print("Valid Phone Number")
    except:
        # print("Invalid phone Number")
        validPhonenumber = False
else:
    # print("Invalid phone Number")
    validPhonenumber = False

# print(validEmail,validPassword,validPhonenumber,validUsername)
if validUsername:
    print("Valid Username")
if validPassword:
    print("Valid Password")
if validEmail:
    print("Valid Email")
if validPhonenumber:
    print("Valid Phone Number")

Its easy Enough to understand as python is a really easy language

Output:-

asmuth@playhouse:~/Desktop/Java Practice$ python test.py
Enter username
username_123
Enter Password
123_Wyti
Enter Email
fake.email@mail.com
Enter your phone number
111-333-4444
Valid Username
Valid Password
Valid Email
Valid Phone Number

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote