0

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

Sabby
  • 2,586
  • 2
  • 27
  • 41
  • possible duplicate of [Best practices for validating email address in Objective-C?](http://stackoverflow.com/questions/800123/best-practices-for-validating-email-address-in-objective-c) – Brad Larson Nov 01 '10 at 19:17

2 Answers2

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.

Hemang
  • 26,840
  • 19
  • 119
  • 186
Swastik
  • 2,415
  • 2
  • 31
  • 61
  • 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
1

I think the regular expression can help you.

NSRegularExpression Class Reference

AechoLiu
  • 17,522
  • 9
  • 100
  • 118