This code is written in java and it is about the validation system.
Conditions:
1. Name Should be 2 or 3 words, first letter of every word should be Capital.
2. Phone No: Should be of length 9 or 10 followed to +92 in every case.
3. Username: any combination of letter with only dot (.) as special character be allowed
4. Password: of length 4-11. with at least one upper case letter, one lower case, one digit and one special character.
Note:
It won't move to next case until you enter the current case correctly.
Code:
import java.util.*;
public class validateinfo
{
int p_check[]=new int[4];
String name,username,password,phone;
int i=-1,n_count=1,check_n=0,f_check=0;
Scanner s=new Scanner(System.in);
public static void main(String args[])
{
validateinfo v=new validateinfo();
v.name();
v.number();
v.username();
v.password();
System.out.println(" -------------------Input Complete-----------------------------");
}
public void name()
{
do{
f_check=0;check_n=0;n_count=1;i=-1;
System.out.println("\nEnter Name=");
name=s.nextLine();
while(i+1<name.length())
{
i++;
if(name.charAt(i)==' ')
{
n_count++;
if(name.charAt(i+1)>=65&&name.charAt(i+1)<=90)
check_n=1;
else
{
check_n=0;
break;
}
}
}
if(n_count>=2&&(name.charAt(0)>=65&&name.charAt(0)<=90)&&check_n==1)
{}
else
{
f_check=1;
System.out.println("\t\t\tInvalid Input\n");
System.out.println("\nName Should be 2 or 3 words, first letter of every word should be capital\n\n\t\t\tEnter Again");
}
}while(f_check!=0);
}
public void number()
{
do{
f_check=0;
System.out.println("\nEnter Phone Number=");
phone=s.nextLine();
if(phone.charAt(0)=='+'&&phone.charAt(1)=='9'&&phone.charAt(2)=='2'&&(phone.length()==12||phone.length()==13))
{}
else
{
f_check=1;
System.out.println("\t\t\tInvalid Input\n");
System.out.println("\nPhone No: Should be of length 9 or 10 followed to +92 in every case. \n\n\t\t\tEnter Again\n");
}
}while(f_check!=0);
}
public void username()
{
do{
f_check=0;i=-1;
System.out.println("\nEnter UserName=");
username=s.nextLine();
if(username.length()>0)
{
while(i+1<username.length())
{
i++;
if((username.charAt(i)>=65&&username.charAt(i)<=90)||(username.charAt(i)>=97&&username.charAt(i)<=122)||username.charAt(i)==46||(username.charAt(i)>=48&&username.charAt(i)<=57))
{
continue;
}
else
{
f_check=1;
System.out.println("\nUsername: any combination of letter with only dot (.) as special character be allowed\n\n\t\t\tEnter Again\n");
break;
}
}
}
else
{
f_check=1;
System.out.println("\t\t\tInvalid Input\n");
System.out.println("\nUsername: any combination of letter with only dot (.) as special character be allowed\n\n\t\t\tEnter Again\n");
}
}while(f_check!=0);
}
public void password()
{
do
{
f_check=0;i=-1;
Arrays.fill(p_check, 0);
System.out.println("\nEnter Password=");
password=s.nextLine();
if(password.length()>=4&&password.length()<=11)
{
while(i+1<password.length())
{
i++;
if(password.charAt(i)>=65&&password.charAt(i)<=90)
p_check[0]++;
else if(password.charAt(i)>=97&&password.charAt(i)<=122)
p_check[1]++;
else if(password.charAt(i)>=48&&password.charAt(i)<=57)
p_check[2]++;
else
p_check[3]++;
}
if(p_check[0]>0&&p_check[1]>0&&p_check[2]>0&&p_check[3]>0)
{}
else
{
f_check=1;
System.out.println("\t\t\tInvalid Input\n");
System.out.println("Password: of length 4-11. with at least one upper case letter, one lower case, one digit and one special character\n\n\t\t\tEnter Again\n\n");
}
}
else
{
f_check=1;
System.out.println("\t\t\tInvalid Input\n");
System.out.println("Password: of length 4-11. with at least one upper case letter, one lower case, one digit and one special character\n\n\t\t\tEnter Again\n\n");
}
}while(f_check!=0);
}
}