Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add +isLikelyEmailAddress as better suited for vague user input.

  • Loading branch information...
commit f3ba44b4563a12fde14774d184c512ffbf7ab136 1 parent ce9a77a
@mikeabdullah mikeabdullah authored
Showing with 19 additions and 1 deletion.
  1. +1 −0  KSURLFormatter.h
  2. +18 −1 KSURLFormatter.m
View
1  KSURLFormatter.h
@@ -49,6 +49,7 @@
+ (NSURL *)URLFromString:(NSString *)string;
+ (BOOL)isValidEmailAddress:(NSString *)address;
++ (BOOL)isLikelyEmailAddress:(NSString *)address; // much the same as above, but ignores some rarities
#pragma mark Managing Behavior
View
19 KSURLFormatter.m
@@ -76,6 +76,23 @@ + (BOOL)isValidEmailAddress:(NSString *)address;
return OK;
}
++ (BOOL)isLikelyEmailAddress:(NSString *)address;
+{
+ BOOL result = [self isValidEmailAddress:address];
+ if (result)
+ {
+ NSURL *URL = [[NSURL alloc] initWithString:address];
+ if (URL)
+ {
+ // Account for strings like http://example.com/@foo which seem to be technically valid as an email address, but unlikely to be one
+ if ([URL scheme]) result = NO;
+ [URL release];
+ }
+ }
+
+ return result;
+}
+
#pragma mark Init & Dealloc
- (id)init
@@ -163,7 +180,7 @@ + (NSURL *)URLFromString:(NSString *)string defaultScheme:(NSString *)fallbackSc
(![result host])) // e.g. foo.com:8888
{
// if it looks like an email address, use mailto:
- if ([self isValidEmailAddress:string])
+ if ([self isLikelyEmailAddress:string])
{
result = [NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", string]];
}
Please sign in to comment.
Something went wrong with that request. Please try again.