Write a java program to check whether a given number is a valid mobile number or not
import java.util.regex.*; class RegexDemo6 { public static void main(String[] args) { Pattern p=Pattern.compile("(0/91)?[7-9][0-9]{9}"); Matcher m=p.matcher(args[0]); if(m.find() && m.group().equals(args[0])) { System.out.println("valid mobile number"); } else { System.out.println("invalid number"); } } }
Output:
1st run : java RegexDemo6 9439202111
valid mobile number
2nd run : java RegexDemo6 929292929292
invalid number
Java Regular expression program to check whether a given mail id is valid or invalid mail id.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc