Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-30-2009, 02:17 AM   #1 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Exclamation How to validate email address field?

Hello,
give me some code to validate email field.
Also other validation code those are mostly used.
vikysaran is offline   Reply With Quote
Old 07-30-2009, 02:26 AM   #2 (permalink)
Registered Member
 
Forsworn's Avatar
 
Join Date: Oct 2008
Location: Germany
Posts: 504
Forsworn is on a distinguished road
Default

Cocoa with Love: Verifying that a string contains an email address using NSPredicate
Forsworn is offline   Reply With Quote
Old 10-12-2009, 06:49 AM   #3 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Red face

Thanx for reply. I tried this-
Code:
NSString *email = textFieldemail.text;
    NSString *emailRegEx =
    @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
    @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
    @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
    @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
    @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
    @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
    @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
    
    NSPredicate *regExPredicate =
    [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];
working great but not if letters are in caps. So how to edit this condition? Also i want user will be able to enter multiple email addresses saperated by ;

Reply soon
__________________
Thanx & Regards-
Vaibhav Saran | Software Engineer
Neo Sypher Systems Pvt. Ltd.
New Delhi | India
Websites:
http://www.iphonesaura.com/
http://www.apptango.com/


Last edited by vikysaran; 10-12-2009 at 11:35 PM.
vikysaran is offline   Reply With Quote
Old 10-15-2009, 02:03 AM   #4 (permalink)
shiva
 
shiva.0537's Avatar
 
Join Date: Jun 2009
Location: Hyderabad
Age: 26
Posts: 54
shiva.0537 is on a distinguished road
Send a message via Skype™ to shiva.0537
Default

Quote:
Originally Posted by vikysaran View Post
Thanx for reply. I tried this-
Code:
NSString *email = textFieldemail.text;
    NSString *emailRegEx =
    @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
    @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
    @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
    @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
    @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
    @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
    @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
    
    NSPredicate *regExPredicate =
    [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];
working great but not if letters are in caps. So how to edit this condition? Also i want user will be able to enter multiple email addresses saperated by ;

Reply soon
Hi,

I am trying same thing but not working for me. Do i need to include any framework or import any class. I am not getting any error also.

Thank you
shiva
shiva.0537 is offline   Reply With Quote
Old 10-15-2009, 02:29 AM   #5 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Default

Quote:
Originally Posted by vikysaran View Post
Hi,

I am trying same thing but not working for me. Do i need to include any framework or import any class. I am not getting any error also.

Thank you
shiva
why not working? could you post the code you using?
__________________
Thanx & Regards-
Vaibhav Saran | Software Engineer
Neo Sypher Systems Pvt. Ltd.
New Delhi | India
Websites:
http://www.iphonesaura.com/
http://www.apptango.com/

vikysaran is offline   Reply With Quote
Old 10-15-2009, 07:27 AM   #6 (permalink)
shiva
 
shiva.0537's Avatar
 
Join Date: Jun 2009
Location: Hyderabad
Age: 26
Posts: 54
shiva.0537 is on a distinguished road
Send a message via Skype™ to shiva.0537
Default

Quote:
Originally Posted by vikysaran View Post
why not working? could you post the code you using?
Hi,

NSString *email = emailTextField.text;
NSString *emailRegEx =
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(??:[a-z0-9](?:[a-"
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(??:25[0-5"
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
@"9][0-9]?|[a-z0-9-]*[a-z0-9]?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";

NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];
if(!myStringMatchesRegEx){
[self showAlertWithText:@"Please enter a valid email address"];
}

This is my code.
Could you please tell me, do i need to import any class or framework?

Thanks
shiva
shiva.0537 is offline   Reply With Quote
Old 11-19-2009, 11:45 PM   #7 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Default

email address should be is small letters. did you notice that?
__________________
Thanx & Regards-
Vaibhav Saran | Software Engineer
Neo Sypher Systems Pvt. Ltd.
New Delhi | India
Websites:
http://www.iphonesaura.com/
http://www.apptango.com/

vikysaran is offline   Reply With Quote
Old 11-20-2009, 02:37 AM   #8 (permalink)
shiva
 
shiva.0537's Avatar
 
Join Date: Jun 2009
Location: Hyderabad
Age: 26
Posts: 54
shiva.0537 is on a distinguished road
Send a message via Skype™ to shiva.0537
Default

Quote:
Originally Posted by vikysaran View Post
email address should be is small letters. did you notice that?
NO,
Thank you for reminding me.
shiva.0537 is offline   Reply With Quote
Old 12-08-2009, 01:14 PM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 61
Kris is on a distinguished road
Default

Quote:
Originally Posted by shiva.0537 View Post
NO,
Thank you for reminding me.
You can simply use [email lowercaseString].
Kris is offline   Reply With Quote
Old 01-25-2010, 07:29 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 30
subodh kumar is on a distinguished road
Default

hi

When i am editing email address again and then checking .it is returning false.

why
thanks
subodh kumar is offline   Reply With Quote
Old 06-21-2010, 04:35 AM   #11 (permalink)
Registered Member
 
vikysaran's Avatar
 
Join Date: Jul 2009
Location: New Delhi
Posts: 130
vikysaran is on a distinguished road
Default

This should also work!...
Code:
    NSArray *validateAtSymbol = [txtLoginId.text componentsSeparatedByString:@"@"];
    NSArray *validateDotSymbol = [txtLoginId.text componentsSeparatedByString:@"."];
    if(([validateAtSymbol count] != 2) || ([validateDotSymbol count] < 2)) {
        
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Invalid EMail Address" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
        [alertView show];
        [alertView release];
        whereClicked = 1;
        return;
    }
__________________
Thanx & Regards-
Vaibhav Saran | Software Engineer
Neo Sypher Systems Pvt. Ltd.
New Delhi | India
Websites:
http://www.iphonesaura.com/
http://www.apptango.com/

vikysaran is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 327
11 members and 316 guests
chiataytuday, coolman, givensur, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,882
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:20 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0