how validate allow characters & special character but not allow number with character or number in kotlin

Advertisements fun main() { val regex = Regex("^[a-zA-Z\\s!@#\$%^&*()-_=+\\\\|\\[{\\]};:’\",<.>/?]*\$") val names = listOf("John Doe", ".Smith", "Alice.", "Doe#Smith", "Doe#Smith99", "65464546499", "MM66M") for (name in names) { if (!name.matches(Regex(".*\\d.*")) || regex.matches(name)) { println("$name is valid") } else { println("$name is invalid") } } } here we expect result John Doe is valid .Smith is valid Alice. is valid… Read More how validate allow characters & special character but not allow number with character or number in kotlin

how do i convert this kotlin code to java

Advertisements Here is a Piece of code in kotlin: val paymentConnection = payment.connect { connectionSucceed { … } connectionFailed { throwable -> … } disconnected { … } } how can i convert it to Java? the prototype in java is shown like this: @NotNull public final poolakey.Connection connect(@NotNull kotlin.jvm.functions.Function1<? super poolakey.callback.ConnectionCallback,kotlin.Unit> callback) >Solution :… Read More how do i convert this kotlin code to java

Checking if a string has no special characters except for ".", "_" and "@"

Advertisements I’m currently writing a script which checks username & password validity. The username should have between 3 and 20 characters and no special characters, except for ".", "_" and "@". Currently, this is my function: fun isValidUsername(username: String): Boolean { var usrnmlength = true var usrnmspecial = true if ((username.length < 3) or (username.length… Read More Checking if a string has no special characters except for ".", "_" and "@"

Kotlin Lambda with receiver accepts random function

Advertisements Hi I am having a kotlin function fun extension(name: String, init: LambdaReceiver.() -> Unit) { val lambdaReceiver = LambdaReceiver(name) lambdaReceiver.init() } where the second parameter accepts a lambda with receiver init: LambdaReceiver.() -> Unit, and the structure of LambdaReceiver looks like class LambdaReceiver(private val name: String) { private var test: Int? = null fun… Read More Kotlin Lambda with receiver accepts random function

Why Kotlin function parameter names break the method call?

Advertisements Wonder what is wrong with specifying Kotlin function parameter name when calling a function. In some situation it won’t work and I don’t know how to fix it. For example, this code works fine without specifying the parameters’ names: assertEquals( FakeDataSource.photosList, repository.getMarsPhotos(), ) But the same code with parameters name give me a compiler… Read More Why Kotlin function parameter names break the method call?