This post will check if a string starts with a number or not in Kotlin.

A simple solution to check if the first character of the string is a digit is using the isDigit() function, which provides support for all Unicode digits.

Download Code

 
Another solution is to extract the first character from the given string and check if that character falls under the numeric ASCII range or not.

Download Code

 
In Kotlin, two comparisons should be converted to a range check:

Download Code

 
Here’s an alternate version using the any() function. It returns true if at least one element matches the supplied predicate.

Download Code

Note that all the above solutions validate that the string is not empty to avoid string index out of range exception. That’s all about checking if a string starts with a number in Kotlin.