Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of restricting account, password, mailbox, ID card and mobile phone number by regular expression

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how regular expressions can restrict accounts, passwords, mailboxes, ID cards, and mobile phone numbers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The specific code is as follows:

# import int main () {/ /? = {0jue 1} / / * = {0, infinite} / / + = {1, infinite} / /\ d = = [0-9] / /\ w = = [A-Za-z_0-9] / / * means dispensable / / [a | b | c] + means that three phone numbers appear at least one or more times / / check whether the phone number is correct NSString * tel = @ " / / regular expression NSString * regex = @ "^\\ dcow $"; / / NSString * regex = @ "^ [0-9] {3 predicate evaluateWithObject:tel 4}-[0-9] {7 predicate evaluateWithObject:tel 8} $"; NSPredicate * predicate = [NSPredicate predicateWithFormat:@ "SELF MATCHES%@", regex]; / / create a predicate NSLog (@ "the phone number:% d", [predicate evaluateWithObject:tel]) that needs to satisfy the above regular expression / / user name (the first digit must be alphabetic, 6-16 digits, and can only have letters, numbers or underscores) NSString * user = @ "m54355"; NSString * regex1 = @ "^ [A-Za-z]\\ w {5NSString 15} $"; NSPredicate * predicate1 = [NSPredicate predicateWithFormat:@ "SELF MATCHES%@", regex1]; / / NSLog (@ "the phone number:% d", [predicate1 evaluateWithObject:user]); / / ID card / / NSString * user1 = @ "610125199301300814" / / NSString * regex2 = @ "^\\ d {17} [\\ dxX] $"; / / NSPredicate * predicate2 = [NSPredicate predicateWithFormat:@ "SELF MATCHES%@", regex2]; / / NSLog (@ "ID card:% d", [predicate2 evaluateWithObject:user1]); / / email NSString * mailbox = @ "101707383@qq.com" NSString * regex3 = @ "^ [a-zA-Z0-9.9% SELF MATCHES%@ -] + @ [A-Za-z0-9.9 -] +\\. [A-Za-z] {2 A-Za-z0 4} $"; NSPredicate * predicate3 = [NSPredicate predicateWithFormat:@ "SELF MATCHES%@", regex3]; / / NSLog (@ "this mailbox:% d", [predicate3 evaluateWithObject:mailbox]); / / Mobile number / / NSString * phone = @ "18709259205"; / / NSString * regex4 = @ "^ 1 [3 | 4 | 5 | 7 | 8]\ d {9} $" / / NSPredicate * predicate4 = [NSPredicate predicateWithFormat:@ "SELF MATCHES%@", regex4]; / / NSLog (@ "this phone:% d", [predicate4 evaluateWithObject:phone]); if ([predicate1 evaluateWithObject:user] = 1) {if ([predicate3 evaluateWithObject:mailbox] = = 1) {NSLog (@ "login success");}} else {NSLog (@ "error");} return 0;} Thank you for reading! This is the end of the article on "how to restrict accounts, passwords, mailboxes, ID cards and mobile phone numbers". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report