1

I need to validate an email address which was in the format dsfdsf@.fdsf.com

As I am new I dont know how to validate the email address.

Please suggest me how to get out of this.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Monish Kumar
  • 2,788
  • 4
  • 38
  • 54
  • possible duplicate of [Best practice for validating email address](http://stackoverflow.com/questions/800123/best-practice-for-validating-email-address) – Brad Larson Aug 10 '10 at 19:57

3 Answers3

2

there you will find the answer :-) What are best practices for validating email addresses in Objective-C for iOS 2.0?

Community
  • 1
  • 1
Ueli
  • 2,301
  • 5
  • 25
  • 29
1
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
if ([emailTest evaluateWithObject:userMailTextField.text] == YES)           
{
   //---- Code for action do you want
}
else
{
   UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:@"Email id is not in proper format" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
   [alert show];
}
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
1

Same way you validate it in any language: examine the string directly, use a regex, etc.

Do some google searches on email validation first though. You'll find it's an area that's incredibly difficult to get right.

wadesworld
  • 13,535
  • 14
  • 60
  • 93