Created
December 30, 2017 01:52
-
-
Save aasumitro/de39c90338de1707507aec995ff93e10 to your computer and use it in GitHub Desktop.
Validation utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package id.asmith.someappclean.utils | |
import android.content.Context | |
import android.net.ConnectivityManager | |
import java.util.regex.Matcher | |
import java.util.regex.Pattern | |
/** | |
* Created by Agus Adhi Sumitro on 23/12/2017. | |
* https://asmith.my.id | |
* aasumitro@gmail.com | |
*/ | |
class Utils { | |
//Cek valid email | |
fun isEmailValid(email: String): Boolean { | |
val pattern: Pattern = Pattern.compile(AppConstants.EMAIL_PATTERN) | |
val matcher: Matcher = pattern.matcher(email) | |
return matcher.matches() | |
} | |
//cek phone validation | |
fun isPhoneValid(phone: String): Boolean { | |
val pattern: Pattern = Pattern.compile(AppConstants.PHONE_PATTERN) | |
val matcher: Matcher = pattern.matcher(phone) | |
return matcher.matches() | |
} | |
//cek username validation | |
fun isUsernameValid (username: String): Boolean { | |
val pattern: Pattern = Pattern.compile(AppConstants.USERNAME_PATTERN) | |
val matcher: Matcher = pattern.matcher(username) | |
return matcher.matches() | |
} | |
//Cek connection | |
fun isNetworkConnected(context: Context?): Boolean { | |
//Connection Manager | |
val cm = context!!.getSystemService(Context.CONNECTIVITY_SERVICE) | |
as ConnectivityManager | |
val activeNetwork = cm.activeNetworkInfo | |
return activeNetwork != null && activeNetwork.isConnectedOrConnecting | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment