Possible Duplicate:
Check that an email address is valid on iOS
What is the regex syntax I can use for email validation in iOS for my UITextField.text value? And is there a way for me to check if other UITextField or UITextView is missing?
Can I use this to test for blank values:
if(content.text == nil){
//do something
}
else{
//proceed with next course of action
}
To be absolutely sure that you have tested for a blank value, you should also test for an empty string.
This construct does it, and leads to less typing than using
isEqualToString:, but it is largely a question of personal preference:People with a more intimate knowledge of the Objective-C runtime might point out that testing for
nilis redundant, as sending a message tonilwill always yield nil (or 0), socontent.text.lengthis nil ifcontent.textis. Also, if your surroundings are populated with hard-core C coders, they could similarly point out that testing for 0 in an if statement is for wimps.Hence, the typing can be reduced to the following, at the cost of some clarity of your code:
As for a regex to test an email address, there is a good discussion here, and the regex in Cocoa can be done like this: