0

How can I do validation for a phone number in Android Saripaar v2?

Does it include a validation class for this, or do I have to write my own?

T.Coutlakis
  • 2,436
  • 1
  • 19
  • 19

1 Answers1

2

(Disclosure: I'm the author)

Hi, phone numbers do not have a universal format and differs from region to region. So, Saripaar doesn't have any built-in validation for phone numbers. You can always create rules that serve your purpose.

To create a custom annotation, see this SO answer.

You can also add a QuickRule that would serve the purpose.

  1. Use the QuickRule if you want to get the job done easily.
  2. If you are looking for reusability and convenience, create a custom annotation. It is a bit more work, but pays off eventually.
Community
  • 1
  • 1
Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
  • Thank you for the clarification. I was confused after seeing `@TextRule(order = 7, message = "Enter valid Phone Number", minLength = 10, maxLength = 14)` from previous version, which didn't work in v2. – T.Coutlakis Mar 21 '15 at 10:43