i would like to check that whether the field entered in the text field is email or not.If its email field then proceed else show some alert or error. I don't know how to validate that field. Please help me out
Asked
Active
Viewed 3,553 times
2 Answers
5
First add RegexKit
to your project.
Import RegexKitLite.h
to the class where you want to check the format
NSString *emailMatchstring=@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b";
compare this string to UITextField
's text.
-
Thanks Sherry but the regular expression you have written is missing something its showing some warnings.I did it with this way without using the RegexKit,Bcoz i downloaded the kit from somewhere ,but some files were missing in that.Here is the simple way which also checks if the letters are capital NSString *emailRegE=@"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"; – Sabby Nov 02 '10 at 05:42