Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using regex for checking string is number, its overengineering #174

Closed
MairwunNx opened this issue Nov 19, 2021 · 1 comment
Closed

Using regex for checking string is number, its overengineering #174

MairwunNx opened this issue Nov 19, 2021 · 1 comment

Comments

@MairwunNx
Copy link

val String.isNumeric: Boolean
get() {
val p = "^[0-9]+$".toRegex()
return matches(p)
}

Using regex for this trivial task its overengineering, by the way, numbers like "3.14" will returns false :).
Never use regex for this, you can just write return "3.14".toFloatOrNull() != null

@FunkyMuse
Copy link
Owner

144ed8e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants