Skip to content

Instantly share code, notes, and snippets.

@chipcerio
Forked from ironic-name/EmailValidator.kt
Created November 10, 2017 08:51
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 chipcerio/9f741767132635dc599bb02db2769cef to your computer and use it in GitHub Desktop.
Save chipcerio/9f741767132635dc599bb02db2769cef to your computer and use it in GitHub Desktop.
Kotlin regex email validator function
fun isEmailValid(email: String): Boolean {
return Pattern.compile(
"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]|[\\w-]{2,}))@"
+ "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
+ "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9]))|"
+ "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"
).matcher(email).matches()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment