Qualcuno può dirmi perché questa valutazione è sempre vera ?!NSTextCheckingResult per i numeri di telefono
L'input è: jkhkjhkj
. Non importa ciò che digito nel campo phone
. E 'vero ogni volta ...
NSRange range = NSMakeRange (0, [phone length]);
NSTextCheckingResult *match = [NSTextCheckingResult phoneNumberCheckingResultWithRange:range phoneNumber:phone];
if ([match resultType] == NSTextCheckingTypePhoneNumber)
{
return YES;
}
else
{
return NO;
}
Ecco il valore della match
:
(NSTextCheckingResult *) $4 = 0x0ab3ba30 <NSPhoneNumberCheckingResult: 0xab3ba30>{0, 8}{jkhkjhkj}
stavo usando RegEx e NSPredicate
ma ho letto che da quando iOS4 si consiglia di utilizzare NSTextCheckingResult
ma posso trovare qualche buon tutorial o esempio su questo.
Grazie in anticipo!
"Consigliato" in quale scenario? Per verificare se un determinato testo è un numero di telefono, questo metodo non è in realtà utile. – darkheartfelt
Elaborare - Posso passare "333-3333-3" (non un numero di telefono valido) alla risposta accettata e ci riesce. – darkheartfelt