package regularexpressions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Mobile {
public static void main(String[] args) {
String num="9177791456";
String form1="[0/91]?[7-9][0-9]{9}";
//String form1="[7-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
//String form1="0?[7-9][0-9]{9}";
//String form1="(0/[+]?91)[7-9][0-9]{9}";here wrong as output
//Pattern p =Pattern.compile("[0/91]?[7-9][0-9]{9}");
//String form1="[a-z][A-Z][a-z A-Z 0-9 . _]*@[a-z A-Z 0-9]+([.][a-z A-Z]+)+";
Pattern p =Pattern.compile(form1);
Matcher m=p.matcher(num);
if(m.find()&&m.group().equals(num)){
System.out.println("valid mobile number");
}
else
{
System.out.println("invalid mobile number");
}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Mobile {
public static void main(String[] args) {
String num="9177791456";
String form1="[0/91]?[7-9][0-9]{9}";
//String form1="[7-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
//String form1="0?[7-9][0-9]{9}";
//String form1="(0/[+]?91)[7-9][0-9]{9}";here wrong as output
//Pattern p =Pattern.compile("[0/91]?[7-9][0-9]{9}");
//String form1="[a-z][A-Z][a-z A-Z 0-9 . _]*@[a-z A-Z 0-9]+([.][a-z A-Z]+)+";
Pattern p =Pattern.compile(form1);
Matcher m=p.matcher(num);
if(m.find()&&m.group().equals(num)){
System.out.println("valid mobile number");
}
else
{
System.out.println("invalid mobile number");
}
}
}
No comments:
Post a Comment