Playing with mobile numbers
Given an number. The task is to tell whether the number is valid indian mobile number or not. Print "Valid" if it is a valid indian mobile number, otherwise print "Invalid".
Rules for valid :-indian mobile number
- The number should contain 10 or 11 or 12 digits.
- If it contains 10 digits, then first digit should be 7 or 8 or 9.
- If it contains 11 digits, then first digit should be 0 and second rule follwed.
- If it contains 12 digits, then first two digits should be 91 and second rule followed .
Input:
The first line contains a single integer T i.e. the number of test cases. Each test case contains a single number(N) in string representing a mobile number
Output:
Output:
Corresponding to each test case, print "Valid" if inumber is valid indian mobile number otherwise printf "Invalid" on a new line.
Constraints:
Constraints:
1<=T<=20
10<= |N| <= 12
10<= |N| <= 12
here |N| denotes the size of number string.
Example:
Example:
Input:
3
07456789011
6782580124
919828689528
07456789011
6782580124
919828689528
Output:
Valid
Invalid
Valid
Invalid
Valid
CODE:
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
//code
Scanner sc=new Scanner(System.in);
int n=Integer.parseInt(sc.nextLine());
while(n>0)
{
String Digit=sc.nextLine();
if(Digit.length()==10)
{
if(Digit.matches("[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else if(Digit.length()==11)
{
if(Digit.matches("[0]{1}[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else if(Digit.length()==12)
{
if(Digit.matches("91[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else
System.out.println("Invalid");
n--;
}
}
}
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
//code
Scanner sc=new Scanner(System.in);
int n=Integer.parseInt(sc.nextLine());
while(n>0)
{
String Digit=sc.nextLine();
if(Digit.length()==10)
{
if(Digit.matches("[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else if(Digit.length()==11)
{
if(Digit.matches("[0]{1}[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else if(Digit.length()==12)
{
if(Digit.matches("91[789]{1}[0-9]{9}"))//valid
System.out.println("Valid");
else
System.out.println("Invalid");
}
else
System.out.println("Invalid");
n--;
}
}
}
Comments
Post a Comment