7 lines
257 B
Scala
7 lines
257 B
Scala
def isNumeric(str: String): Boolean = {
|
|
!throwsNumberFormatException(str.toLong) || !throwsNumberFormatException(str.toDouble)
|
|
}
|
|
|
|
def throwsNumberFormatException(f: => Any): Boolean = {
|
|
try { f; false } catch { case e: NumberFormatException => true }
|
|
}
|