Verify Mobile Number Valid or Invalid
Program:
Valid Mobile Number:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package javabasics; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MobileValidation { public static void main(String[] args) { String mn ="9254256"; String form1="[0/91]?[7-9][0-9]{9}"; Pattern p =Pattern.compile(form1); Matcher m=p.matcher(mn); if(m.find()&&m.group().equals(mn)) { System.out.println("Valid mobile number"); } else { System.out.println("Invalid mobile number"); } } } |
Output:
Valid mobile number
Invalid Mobile Number:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package javabasics; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MobileValidation { public static void main(String[] args) { String mn ="9254256"; String form1="[0/91]?[7-9][0-9]{9}"; Pattern p =Pattern.compile(form1); Matcher m=p.matcher(mn); if(m.find()&&m.group().equals(mn)) { System.out.println("Valid mobile number"); } else { System.out.println("Invalid mobile number"); } } } |
Output:
Invalid mobile number