Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.*;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String fullName = "";
- String gender = "";
- int age = 0; //done
- String dob = "";
- String cnic = "";
- String email = "";
- String address = "";
- String cellPhone = "";
- String landLine = "";
- String username = "";
- String password = "";
- System.out.println("FullName (SPECIAL CHARACTERS AND NUMBERS ARE NOT ALLOWED, ONLY SALUTATIONS ARE!)");
- fullName = input.nextLine();
- while(!regexChecker("^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", fullName)){
- System.out.println("Invalid Format, please renter your FullName with the proper format");
- fullName = input.nextLine();
- }
- System.out.println("Gender (MALE / FEMALE / M / F)");
- gender = input.nextLine();
- while(!regexChecker("^M|MALE|F|FEMALE$", gender)){
- System.out.println("Invalid Gender, please renter your Gender with the proper Format!");
- gender = input.nextLine();
- }
- System.out.println("Age (YOU MUST BE OLDER THAN 18 YEARS)");
- age = input.nextInt();
- if(age < 18){
- System.out.println("Below 18 are not allowed to enter, terminating program!");
- System.exit(0);
- }
- System.out.println("Date of Birth (DD/MM/YYY)");
- dob = input.nextLine();
- while(!regexChecker("^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)$", dob)){
- System.out.println("Invalid Format/Date, please renter your DOB with the proper format");
- dob = input.nextLine();
- }
- System.out.println("CNIC number");
- cnic = input.nextLine();
- while(!regexChecker("^([0-9]{6})( |-)?([0-9]{6})( |-)?([0-9]{1})$", cnic)){
- System.out.println("Invalid CNIC, please renter your CNIC with the proper format");
- cnic = input.nextLine();
- }
- System.out.println("Email Address");
- email = input.nextLine();
- while(!regexChecker("^[A-Za-z0-9._%-]+@[A-Za-z0-9]+\\.[A-Za-z]{2,4}$", email)){
- System.out.println("Invalid Format, please renter your Email with the proper format");
- email = input.nextLine();
- }
- System.out.println("Address");
- address = input.nextLine();
- while(!regexChecker("^(.){0,50}$", address)){
- System.out.println("Your address should not be longer than 50 characters");
- address = input.nextLine();
- }
- System.out.println("Cellphone number");
- cellPhone = input.nextLine();
- while(!regexChecker("^(((00|\\+)?(923))[0-9]{9})|((03)[0-9]{9})$", cellPhone)){
- System.out.println("Invalid number, please renter your number with the proper Format!");
- cellPhone = input.nextLine();
- }
- System.out.println("Landline number (STARTS WITH 021 OR 3)");
- landLine = input.nextLine();
- while(!regexChecker("^((021)( |-)?)?(3)[0-9]{7}$", landLine)){
- System.out.println("Invalid number, please renter your number with the proper Format!");
- landLine = input.nextLine();
- }
- System.out.println("Username");
- username = input.nextLine();
- while(!regexChecker("^(.){0,6}$", username)) {
- System.out.println("Your username should not be longer than 6 characters");
- username = input.nextLine();
- }
- System.out.println("Password (ATLEAST 1 LETTER IN CAPITAL, ATLEAST 1 NUMBER, ATLEAST LETTER IN SMALL");
- password = input.nextLine();
- while (!regexChecker("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$", password)) {
- System.out.println("Invalid");
- password = input.nextLine();
- }
- System.out.println("Full Name" + fullName);
- System.out.println("Gender" + gender);
- System.out.println("Age" + age);
- System.out.println("Date of Birth" + dob);
- System.out.println("CNIC" + cnic);
- System.out.println("Email" + email);
- System.out.println("Address" + address);
- System.out.println("Cell Phone" + cellPhone);
- System.out.println("Landline" + landLine);
- System.out.println("Username" + username);
- System.out.println("Password" + password);
- }
- public static boolean regexChecker(String theRegex, String str2Check) {
- Pattern checkRegex = Pattern.compile(theRegex);
- Matcher regexMatcher = checkRegex.matcher(str2Check);
- return regexMatcher.find();
- }
- }
Add Comment
Please, Sign In to add comment