TextView judgment format, user name, verification code

Source: Internet
Author: User

#pragma mark- detect illegal characters

Names can only be made up of Chinese, letters or numbers

-(BOOL) Isvalidateuser: (nsstring *) text

{

nsstring * regex = @ "^[a-za-z0-9_\u4e00-\u9fa5]+$";

Nspredicate *pred = [nspredicate predicatewithformat:@ "self MATCHES%@", regex];

return [pred evaluatewithobject:text];

}

Verification code, from 0 to 9, 6 digits

-(BOOL) Isvalidatenumber: (nsstring *) text

{

NSString * regex = @ "^[0-9]{6}";

Nspredicate *pred = [nspredicate predicatewithformat:@ "self MATCHES%@", regex];

return [pred evaluatewithobject:text];

}

In the Uialert method.

-(void) Alertview: (uialertview *) Alertview clickedbuttonatindex: (nsinteger) buttonindex

{

XLOG (@ "%d", buttonindex);

if (Buttonindex = = 1)

{

// get input box

Uitextfield *tf=[alertview Textfieldatindex:0];

if ([TF. Text Trimwhitespace]. length <= 0)

{

[Mthint Toast:@ " cannot be empty " toview:self. View displaytime:2.0f];

return;

}

if (![ self isvalidateuser:tf. Text])

{

[Mthint Toast:@ " name can only be made up of Chinese, letters, or numbers " toview: Self. View displaytime:2.0f];

return;

}

if (TF. Text. length >= )

{

[Mthint Toast:@ ' name needs to be less than ten characters ' toview: Self. View displaytime:2];

return;

}

[titlevalues replaceobjectatindex:1 withobject: Tf.text];

namevalue = tf. text;

XLOG (@ "%@", TF. text);

[_tableview reloaddata];

}

}

TextView judgment format, user name, verification code

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.