This Study Resource Was: CSE 1007 Lab Activity-6
This Study Resource Was: CSE 1007 Lab Activity-6
Lab Activity-6
Name: S Jayakishore Reg No: 16BIS0041
m
message ‘valid’ else ‘invalid’.
e r as
co
CODE:
eH w
import java.util.*;
o.
import java.util.regex.*;
rs e
ou urc
import java.lang.*;
public class lab6{
o
aC s
{
ed d
int a=0,b=0;
ar stu
String regNo,mobNo;
Scanner in=new Scanner(System.in);
sh is
regNo=in.nextLine();
try{if(regNo.length()!=9)
{
a=1;
throw new IllegalArgumentException("Length of Registration
number should be 9");
}}
catch(Exception e)
https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/
{
System.out.println(e);}
try{if(!Pattern.matches("[0-9]*[a-z]*[A-Z]*[0-9]*[a-z]*[A-Z]*",regNo))
{
a=1;
throw new NoSuchElementException("Registration number
should have only numbers and alphabets");
}}
catch(Exception e){
System.out.println(e);
m
e r as
}
co
eH w
System.out.println("Please enter the mobile number: ");
o.
mobNo=in.nextLine();
rs e
ou urc
try{
if(mobNo.length()!=10)
o
{
aC s
v i y re
b=1;
throw new IllegalArgumentException("Lengths do not match");
ed d
}}
ar stu
catch(Exception e)
{
sh is
System.out.println(e);
Th
}
try{if(!Pattern.matches("[0-9]+",mobNo))
{
b=1;
throw new NumberFormatException("mobile number should
contain only numbers!!");
}}
catch(Exception e){
https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/
System.out.println(e);
}
if(a==1)
System.out.println("Invalid registration number");
else if(a==0)
System.out.println("Valid registration number");
if(b==1)
System.out.println("Invalid mobile number");
else if(b==0)
m
System.out.println("Valid mobile number");
e r as
co
}}
eH w
o.
OUTPUT:
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/39866238/lab6-16bis0041pdf/