i want validate textfield of email , wants find out techmahindra email or not. how can find . attaching code here. 1 suggest changes.
nsstring * mystring = @ "@"; nsarray * mywords = [emailstr componentsseparatedbystring: mystring]; nsstring * str = [mywords objectatindex: 1]; if ([str isequaltostring: @ "techmahindra.com"]) { nsstring * emailregex = @ "[a-z0-9a-z._%+]+@[a-za-z0-9.]+\\.[a-za-z]{2,4}"; nspredicate * emailtest = [nspredicate predicatewithformat: @ "self matches %@", emailregex]; return [emailtest evaluatewithobject: emailstr]; } else return no;
given have written code extract part of string follows @ symbol, don't need regular expressions there. can case-insensitive comparison, this:
if (str != nil && [str compare:@"techmahindra.com" options:nscaseinsensitivesearch]) { return [emailtest evaluatewithobject:emailstr]; } else return no; you should trim whitespace part of email validation code check fail if there trailing space example.
Comments
Post a Comment