Reputation: 1303
Hello I am working on app which need mobile number as unique key, I comeup with 4 diff conditions as below:
for e.g. number is: 8888822222 that can be saved in any users contact book as:
Although above 4 are the same number but that could be different in the case of string.
So how to check and consider this 4 as same number. Can anyone help me ?
EDIT
My question is what should I consider in case of numbers with diff country codes and different contact number length.
Upvotes: 1
Views: 229
Reputation: 64
Maybe this is gonna help you
if(String(phone.characters.prefix(4)) == ("0888")){
phone = String(phone.characters.dropFirst())
}else if(String(phone.characters.prefix(3)) == ("+18")){
phone = phone.textureName.replacingOccurrences(of: "+1", with: "", options: NSString.CompareOptions.literal, range:nil)
}else if(String(phone.characters.prefix(3)) == ("+10")){
phone = phone.textureName.replacingOccurrences(of: "+10", with: "", options: NSString.CompareOptions.literal, range:nil)
}else {
//
}
Upvotes: 0
Reputation: 72450
All your phone number has at least 10 digits length, So you can get last 10 digit from your contact number string and check that any unique key field contains that string.
For eg
let contactNumStr = "+18888822222"
let onlyNum = contactNumStr.substring(from:contactNumStr.index(contactNumStr.endIndex, offsetBy: -10))
//8888822222 will be store in onlyNum
Now you can check in your database that any unique number contains
this onlyNum
.
Note that you need to check for contains
not the exact match.
Upvotes: 1