Wednesday 15 January 2014

Java Regex for Indian Mobile Number

 public class RegExTest {  
   public static void main(String arg[]) {  
     String str = "0888"; //"+91989898" "9180709709"  
     String regex="^([\\+](91))+([0-9]+$)|(^(0))+([0-9]+$)"; //{10} if you want to give no limit  
     Pattern pat = Pattern.compile(regex);  
     Matcher mat= pat.matcher(str);  
     if (mat.matches()) {  
       System.out.println("String matched");  
     } else {  
       System.out.println("String not matched");  
     }  
   }  
 }  


To give number limit use this regex:

String regex="^([\\+](91))+([0-9]{10}$)|(^(0))+([0-9]{10}$)"; 

Here {10} means after 0 or +91 must be 10 number

Things after Kotlin Android Extensions

Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...