iOS to determine whether the expression and mailbox format are judged

Source: Internet
Author: User

1. The method is seen from the forum, the use of their own under the feeling is very useful, do a memo here!!!!!

2. Application environment, when the user enters the nickname, can not enter the expression


-(BOOL) Stringcontainsemoji: (nsstring *) string {

__block BOOL returnvalue =NO;

[String enumeratesubstringsinrange:nsmakerange(0, [stringlength])options :nsstringenumerationbycomposedcharactersequencesusingblock:

^ (nsstring *substring,nsrange substringrange,nsrange enclosingrange, BOOL *stop ) {

Const Unichar hs = [substringcharacteratindex: 0];

//surrogate pair

if (0xd800 <= HS && HS <= 0XDBFF) {

if (substring. length > 1) {

Const unichar ls = [substringcharacteratindex: 1];

Const int UC = ((hs-0xd800) * 0x400) + (LS-0XDC00) + 0x10000;

if (0x1d000 <= UC && UC <= 0x1f77f) {

returnvalue =YES;

}

}

}Elseif (substring. Length > 1) {

Const unichar ls = [substringcharacteratindex: 1];

if (ls = = 0x20e3) {

returnvalue =YES;

}

}Else {

//Non Surrogate

if (0x2100 <= HS && HS <= 0X27FF) {

returnvalue =YES;

}Elseif (0x2b05 <= HS && HS <= 0x2b07) {

returnvalue =YES;

}Elseif (0x2934 <= HS && HS <= 0x2935) {

returnvalue =YES;

}Elseif (0x3297 <= HS && HS <= 0x3299) {

returnvalue =YES;

}Elseif (hs = = 0XA9 | | hs = = 0XAE | | hs = = 0X303D | | hs = = 0X3030 | | hs = = 0X2B55 | | hs = = 0X2B1C | | hs = = 0x2b1b | | HS = = 0X2B50) {

returnvalue =YES;

}

}

}];

return returnvalue;

}



E-Mail interpretation

Determine if it is a mailbox format

-(BOOL) Isvalidateemail: (nsstring *) Email

{

nsstring *emailregex =@ "[a-z0-9a-z._%+-]+@[a-za-z0-9.-]+\\. [A-za-z] {2,4} ";

nspredicate *emailtest = [nspredicatepredicatewithformat:@ "Self matches%@" , Emailregex];

return [Emailtest evaluatewithobject: email];

}



iOS to determine whether the expression and mailbox format are judged

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.