Skip to content

Instantly share code, notes, and snippets.

@dcampogiani
Created December 24, 2017 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcampogiani/5101541b8415d058d05b56f088bd6113 to your computer and use it in GitHub Desktop.
Save dcampogiani/5101541b8415d058d05b56f088bd6113 to your computer and use it in GitHub Desktop.
val VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE)!!
val VALID_PHONE_NUMBER_ADDRESS_REGEX = Pattern.compile("\\d{10}|(?:\\d{3}-){2}\\d{4}|\\(\\d{3}\\)\\d{3}-?\\d{4}", Pattern.CASE_INSENSITIVE)!!
fun validMail(input: String): Boolean {
val matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(input)
return matcher.find()
}
fun validNumber(input: String): Boolean {
val matcher = VALID_PHONE_NUMBER_ADDRESS_REGEX.matcher(input)
return matcher.find()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment