validating the data

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

  1. rethish macrumors member

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


    Jan 10, 2005
    Dallas, TX
    NSPredicate can do some (from what I can tell) basic string matching using predicateWithFormat:.

    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.

  3. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    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

    Oct 16, 2008
    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