In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how iOS implements regular expressions to judge pure 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 first one uses regular expressions to judge.
/ / whether it is pure number + (BOOL) isNumText: (NSString *) str {NSString * regex = @ "(/ ^ [0-9] * $/)"; NSPredicate * pred = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", regex]; BOOL isMatch = [pred evaluateWithObject:str]; if (isMatch) {return YES;} else {return NO;}}
Whether the specific rules are correct or not, we still need to take a look at the following
The second system is derived from
I recommend the second one.
-(NSString *) trimming {return [self stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];} / / determine whether it is a pure number [NSCharacterSet decimalDigitCharacterSet]; if ([[textField.text stringByTrimmingCharactersInSet: [NSCharacterSet decimalDigitCharacterSet]] trimming] .length > 0) {DLog (@ "not a pure number");} else {DLog (@ "pure number!") ;}
Recently, I am working on an instant messaging project, the first is the registration login interface, the requirement of the project is to obtain a 4-digit CAPTCHA from the mobile phone number entered by the user to complete the registration, so what's the problem?
How to determine that the mobile phone number entered by the user is legal and correct 11-digit mobile phone number? (these simple questions are judged at the front end and then post to the background. There is no need to post all kinds of useless data to the background.)
There are many ways to judge whether the mobile phone number is correct. I use regular expressions to complete the matching. I don't say much nonsense and go directly to the code:
/ / regular expressions match 11-digit mobile phone numbers NSString * regex = @ "^ ((13 [0-9]) | (15 [^ 4,\\ D]) | (18 [0meme 0-9]))\\ d {8} $"; NSPredicate * pred = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", regex]; BOOL isMatch = [pred evaluateWithObject:_telField.text] If (isMatch) {/ / valid mobile number} else// invalid mobile number {if (ios7) {UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:@ "invalid mobile number, please re-enter." Delegate:self cancelButtonTitle:nil otherButtonTitles:@ "OK", nil nil]; alertView.tag = 104; [alertView show];} else {UIAlertController*alertController = [UIAlertController alertControllerWithTitle:nil message:@ "invalid mobile phone number, please re-enter." PreferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* otherAction = [UIAlertAction actionWithTitle:@ "determine" style:UIAlertActionStyleDefault handler: ^ (UIAlertAction*action) {[_ telField selectAll:self];}]; [alertController addAction:otherAction]; [self presentViewController:alertController animated:YES completion:nil];}
Unicom, Mobile and Telecom add new numbers every year, so regular expressions that match phone numbers need to be updated year after year.
^ ((13 [0-9]) | (15 [^ 4,\ D]) | (18 [0d0-9]))\\ d {8} $this regular expression I have tested and haven't found any numbers that don't match. Share it here!
Thank you for reading! On "iOS how to achieve regular expressions to judge pure numbers" this article is shared here, 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 out for more people to see it!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.