Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created March 15, 2020 16:34
Show Gist options
  • Select an option

  • Save foxicode/ac892cda68440fcb779766e3590fd450 to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/ac892cda68440fcb779766e3590fd450 to your computer and use it in GitHub Desktop.
Kotlin String extension to analyze content
val String.containsLatinLetter: Boolean
get() = matches(Regex(".*[A-Za-z].*"))
val String.containsDigit: Boolean
get() = matches(Regex(".*[0-9].*"))
val String.isAlphanumeric: Boolean
get() = matches(Regex("[A-Za-z0-9]*"))
val String.hasLettersAndDigits: Boolean
get() = containsLatinLetter && containsDigit
val String.isIntegerNumber: Boolean
get() = toIntOrNull() != null
val String.toDecimalNumber: Boolean
get() = toDoubleOrNull() != null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment