https://kotlinlang.org logo
#getting-started
Title
# getting-started
h

hoos

10/12/2023, 4:26 PM
Can anyone share their experience/recommendations for validation libraries? I'm looking for something that is simple to use, comes with predefined validations for things like email addresses, mobile numbers, etc. It should also be easily extensible and customisable with support for customer error messages and error codes. Thanks in advance.
j

Jacob

10/12/2023, 5:10 PM
Hibernate?
👀 1
h

hoos

10/12/2023, 5:53 PM
Interesting option. I was thinking more along these lines: https://medium.com/nerd-for-tech/object-validation-in-kotlin-c7e02b5dabc
c

CLOVIS

10/12/2023, 8:02 PM
I've seen a few libraries that attempt to do this. The most credible seems to be https://github.com/arrow-kt/arrow-exact, purely because multiple library authors have looked into it
👍 1
Email addresses and phone numbers are always going to be an issue though. The email RFC is much more complicated than most people assume. The phone number spec is completely different from one country to another. The only reliable strategy is to send an email/SMS to that number, and ask the user to prove they received it. Other than that, it's not worth trying to do any complicated tests other than maybe "an email should have an @" and a max-size check to avoid DoS attacks
☝️ 2
👍 1
c

Chris Fillmore

10/12/2023, 10:25 PM
Agreed that “the best way to know if an email is valid is just to send it mail”
j

Jeff Lockhart

10/12/2023, 10:42 PM
For phone number validation, I've used Google's library.
👍 1
c

CLOVIS

10/13/2023, 8:07 AM
Thanks for the link. Now we have to find someone willing to make a KMP wrapper for it, since it already supports Java, JS and C++ (with different codebases)
💯 1
h

hoos

10/13/2023, 8:23 AM
Thanks for all suggestions everyone. Greatly appreciated.
2 Views