Syntax and usage of regular expression functions for user names and passwords in iOS development

Source: Internet
Author: User

For the login function of the app, when landing, in order to reduce unnecessary costs of the server, user name and password before users submit to the server, must first in the app to do a basic verification, such as the basic limit for how many Ah, is composed of letters or the combination of words and numbers, etc. These qualifications and requirements require our programmers to write regular function expressions to deal with the nonsense, not much said:

Explanation: For example, password, first

Write a regular expression with a string

NSString * pattern = @ "^[a-za-z0-9]{6,16}$";
which
The meaning of regular expressions is limited to 6 to 16 bits of English-sized letters and numbers.

Specific about the regular expression of the symbolic meaning will be reflected in later articles, this article is not detailed, but the role of law;

The meaning of this sentence is to create a predicate, and then this predicate follows the regular expression to ask

Nspredicate *pred = [Nspredicate predicatewithformat:@ "Self MATCHES%@", pattern];

Finally, define a bool variable and see if it conforms to the regular expression to return both Yes and No.

BOOL IsMatch = [pred Evaluatewithobject:password];

Syntax and usage of regular expression functions for user names and passwords in iOS development

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.