validating the data

Discussion in 'Mac Programming' started by rethish, Nov 6, 2008.

  1. rethish macrumors member

    Joined:
    Oct 16, 2008
    #1
    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, 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.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #3
    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.
     
  4. rethish thread starter macrumors member

    Joined:
    Oct 16, 2008
    #4
    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
     

Share This Page