Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my project i have validate a phone number with country code like if user enter number is 44557788991 and select country US.same like for other country how can i check the phone number is valid or not.

enter image description here

on button click i have to check number is valid or not.

share|improve this question
Did you mean you want to check the number exists or not ? – Maulik 6 hours ago
i want to check number by country code like user select US then number according to number format. @Maulik – chetu 6 hours ago
The question itself is silly. – TBlue 2 hours ago

2 Answers

Try this one:---

NSString* yourPhoneNo=@"44557788991";

NSString *regex = @"^((\\+)|(00))[0-9]{6,14}$";
NSPredicate *validation = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

BOOL isValidate = [validation evaluateWithObject:yourPhoneNo];

Or this one:---

NSString *stringToBeTested = @"8123456789";

NSString *mobileNumberPattern = @"[789][0-9]{9}";
NSPredicate *mobileNumberPred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobileNumberPattern];

BOOL matched = [mobileNumberPred evaluateWithObject:stringToBeTested];
share|improve this answer
1  
This doen't answer the country specific part of the question. – Guillaume Algis 5 hours ago

I think you want to check the number country wise. for this you have to use following demo

https://github.com/rmaddy/RMPhoneFormat

for UK

    RMPhoneFormat *fmt = [[RMPhoneFormat alloc] initWithDefaultCountry:@"uk"];
    NSString *numberString = // the phone number to format
    NSString *formattedNumber = [fmt format:numberString];

for Australia

RMPhoneFormat *fmt = [RMPhoneFormat instance];
NSString *callingCode = [fmt callingCodeForCountryCode:@"AU"]; // Australia - returns 61
NSString *defaultCallingCode = [fmt defaultCallingCode]; // based on current Region Format (locale)

and so on...

share|improve this answer
this is good but i want to check something like in first textField user enter phone number and then select country code after this i click on button and want to get out put like... Number:1234567890 Code:IN isValidPhoneNumber ? [YES] 164 : +911234567890 INTERNATIONAL : +91 1234 567 890 NATIONAL : 01234 567 890 FC3966 : tel:+91-1234-567-890 extractCountryCode [82] extractCountryCode [82] [3213123123]. i get this out using github.com/me2day/libPhoneNumber-iOS. but when i call send time my app is crash @SAMIR RATHOD – chetu 4 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.