Assuming that you want to not only convert using Try(x.toInt) or Try(x.toFloat) , but you really want the validator to accept String and return true if the passed String can be converted to A with implicit evidence: Numeric[A] .
Then I would say: Afaik, no , this is impossible. Moreover, Numeric not sealed. That is, you can create your own Numeric implementations
Primitive types, such as Int, Long, Float, Double , can be easily extracted using regular expressions.
source share