IPhone simple phone number validation

后端 未结 3 450
别跟我提以往
别跟我提以往 2020-12-09 06:56

I find all kinds of phone number validations on stackoverflow for the iphone but none seem to validate they just seem to change the format. example Phone number formatting.

3条回答
  •  [愿得一人]
    2020-12-09 07:21

    First, real phone number validation is pretty complicated. Are you limiting yourself to NANP (North America Numbering Plan), or are you looking for E.164 numbers? It looks like you're trying to mostly match E.164, though this isn't usually the kind of number that most people would enter.

    Your match requires a plus, followed by a sequence of digits between seven and fifteen long with optional spaces between them. Is this what you mean? What strings are you passing in?

    Note that as of iOS4, there is NSRegularExpression that is a bit better for this than NSPredicate.

提交回复
热议问题