發表文章

目前顯示的是 1月, 2016的文章

Good Regex Detecting for Website URL, ISBN, GUID - Java

// web site url public static boolean WebsiteURL(final String str) {     if(str == null) return false;     String regex = " ^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|] ";     Pattern pattern = Pattern.compile( regex );     return pattern.matcher( str.toString() ).matches(); }     // ISBN 國際標準書號 public static boolean LibraryISBN(final String str) {     if(str == null) return false;         String regex = " ^(/d[- ]*){9}[/dxX]$ ";     Pattern pattern = Pattern.compile( regex );     return pattern.matcher( str.toString() ).matches(); }     // GUID 全球唯一標識符 public static boolean GUID(final String str) {     if(str == null) return false;         String regex = " ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ";     Pattern pattern = Pattern.compile( regex );     return pattern.matcher( str.toString() ).matches(); }

How to detect email address format - Android, Java coding

1. First import java.util.regex.Pattern. 2. Email regex is ^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$ 3. Use Pattern.compile( [email regex string] ). Finally, coding method like below. public static boolean checkEmail( final String mail ) {     if( mail != null )     {         String EMAIL_PATTERN = " ^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$ ";     Pattern pattern = Pattern.compile( EMAIL_PATTERN ) ;     return pattern.matcher( mail ).matches() ;     }     return false; }