How can we validate a string consist any single alphabets or not in scala?
My application takes in a string like this:
I need to validate in a Scala script that the string consists of any single alphabet or not.
Consider exists method over a given string, which maps each character onto a predicate provided. For instance, Char.isLetter proves true only if a given character is an alphabetical value (a letter). Hence
"P700058213111115432196".exists(_.isLetter) Boolean = true
"700058213111115432196".exists(_.isLetter) Boolean = false
Similarly with forall we can verify that each and every character in a string holds a predicate, for instance
"P700058213111115432196".forall(_.isDigit) Boolean = false
"700058213111115432196".forall(_.isDigit) Boolean = true
To remark that both exists and forall iterate over a collection. Here we iterate over a Scala string which is treated as a sequence of Char.