Recently, I came accross this excellent tool to validate and visualize Regular Expressions. I thought of implementing a small problem using regex and validate it from there.
REGEX: ^\s*\d*([.]\d+|\d+[.]|\d+[eE]\d+){0,1}\d*\s*$
func isNumber(_ s: String) -> Bool {
let regex = "^\\s*\\d*([.]\\d+|\\d+[.]|\\d+[eE]\\d+){0,1}\\d*\\s*$"
let predicate = NSPredicate(format: "SELF MATCHES %@", argumentArray: [regex])
return predicate.evaluate(with: s)
}