Do this programming assignment in Java Programming. 1) [10 points] Write a progr
ID: 3889994 • Letter: D
Question
Do this programming assignment in Java Programming.
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
import java.io.*;
import java.util.*;
public class DemoRegular {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter password :");
String passwd = sc.nextLine();
String pattern1 = "(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[-])(?=\S+$).{6,}";
if (passwd.matches(pattern1)){
System.out.println("Valid input");
}
else {
System.out.println("Invalid input");
}
String pattern2 = "(?=.*[a-z])(?=.*[_])(?=\S+$).{1,}";
System.out.println("Enter username :");
String username = sc.nextLine();
if (username.matches(pattern2)){
System.out.println("Valid input");
}
else {
System.out.println("Invalid input");
}
String pattern3 = "(?=.*[0-9])(?=.*[-])(?=\S+$).{12,}";
System.out.println("Enter phone :");
String phone = sc.nextLine();
if (phone.matches(pattern3)){
System.out.println("Valid input");
}
else {
System.out.println("Invalid input");
}
String pattern4 = "(?=.*[@])(?=\S+$).{1,}";
System.out.println("Enter e-mail :");
String email = sc.nextLine();
if (email.matches(pattern4)){
System.out.println("Valid input");
}
else {
System.out.println("Invalid input");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.