I need to determine if a text is an email address, or mobile number, for email address I can use some regular expression, for mobile number I can check if the string has only digits(right?)
and the sequence is like:
is (regex_valid_email(text))
{
// email
}
else if (all_digits(text))
{
// mobile number
}
but how do I check if a string has only numbers in iOS?
Thanks
You create an NSCharacterSet that includes the digits and probably the dash and maybe parentheses (depending on what format you are seeing for the phone numbers). You then invert that set, so you have a set that has everything but those digits and things, then use rangeOfCharactersFromSet and if you get anything but NSNotFound, then you have something other than digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With