I’m trying to check if some email address is correct with the following code :
NSPredicate *regexMail = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*@.*\..*'"];
if([regexMail evaluateWithObject:someMail])
...
But the “\.” doesn’t seem to work since the mail “smith@company” is accepted. Besides, I have the following warning : “Unknown escape sequence”
Edit :
I’m programming in Objective-C for iPhone.
Thanks
You cannot correctly validate an email address with regular expressions alone. A simple search will show you many articles discussing this. The problem lies with the nature of DNS: there are too many possible domain names (including non-english and Unicode domains), you cannot correctly validate them using a regex. Don’t try.
The only correct way to determine if an email address is valid is to send a message to the address with a unique URL that identifies the account associated with the email, for the user to click. Anything else will annoy your end-user.