Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rethish

macrumors member
Original poster
Oct 16, 2008
41
0
I am confused of validating some of the fields such as email_id ,web address in my project.These fields should accept the standard format (for eg: aaaa@aaa.com, http://www.ddd.com). How can i do this? I m a biginner in mac programming . I use xcode 3.1 , I B 3.1 and objective-C for programming . Please give me some tips with examples to overcome this problem .

thank you.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
NSPredicate can do some (from what I can tell) basic string matching using predicateWithFormat:.
http://developer.apple.com/document.../NSPredicate_Class/Reference/NSPredicate.html

There are other regular expression libraries for download (RegexKitLite was one of the first results). However, be aware that email address validity is defined by RFC-5322 and RFC-5321, and it is much more complicated than you expect. You can certainly only accept a subset of valid email addresses, but be warned that one *could* have an email address that your simplified expression doesn't accept.

-Lee
 

ChrisA

macrumors G5
Jan 5, 2006
12,919
2,173
Redondo Beach, California
I am confused of validating some of the fields such as email_id ,web address in my project.These fields should accept the standard format (for eg: aaaa@aaa.com, http://www.ddd.com). How can i do this? I m a biginner in mac programming . I use xcode 3.1 , I B 3.1 and objective-C for programming . Please give me some tips with examples to overcome this problem .

thank you.

When possable I always like to use the standard functions that are available in all Unix-like (or "POSIX") systems.

Take a look at the "regcomp" man page. You would write a regular expression for the strings you want to accept then "compile" that expression with regcomp(). Then compare your strings using the compiled expression with regexec(). It will be very fast in your case because you only have to compile once. These functions will work on Mac OS X, Solaris, Linux and even on Windows systems without change.

You can test your regular expression with a command like "grep" before you start to write code.
 

rethish

macrumors member
Original poster
Oct 16, 2008
41
0
thank you

First i wud like to thank you for responding to my post.

But it look a little bit strange for me ,as i m a beginner in mac programming. Please show me a detailed way to overcome the problem .

thank you
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.