Skip to content

Instantly share code, notes, and snippets.

@akshaykalola28
Created March 1, 2023 13:19
Show Gist options
  • Save akshaykalola28/375898fcddd6be4d1b1a3aa13d615b78 to your computer and use it in GitHub Desktop.
Save akshaykalola28/375898fcddd6be4d1b1a3aa13d615b78 to your computer and use it in GitHub Desktop.
Extension function to check the string is digit only, alphabetic only or alphanumeric only.
val String.isDigitOnly: Boolean
get() = matches(Regex("^\\d*\$"))
val String.isAlphabeticOnly: Boolean
get() = matches(Regex("^[a-zA-Z]*\$"))
val String.isAlphanumericOnly: Boolean
get() = matches(Regex("^[a-zA-Z\\d]*\$"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment