- Validity judgment of mobile phone number
- Detect if it is a mobile phone number
- -(BOOL) Ismobilenumber: (nsstring *) mobilenum
- {
- /**
- * Mobile phone number
- * Mobile: 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
- * Unicom: 130,131,132,152,155,156,185,186
- * Telecom: 133,1349,153,180,189
- */
- NSString * MOBILE = @ "^1 (3[0-9]|5[0-35-9]|8[025-9]) \\d{8}$";
- /**
- 10 * Mobile: China Mobile
- 11 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
- 12 */
- NSString * CM = @ "^1 (34[0-8]| ( 3[5-9]|5[017-9]|8[278] \\d) \\d{7}$ ";
- /**
- 15 * Unicom: China Unicom
- 16 * 130,131,132,152,155,156,185,186
- 17 */
- NSString * CU = @ "^1 (3[0-2]|5[256]|8[56]) \\d{8}$";
- /**
- 20 * China Telecom: Telecom
- 21 * 133,1349,153,180,189
- 22 */
- NSString * CT = @ "^1 ((33|53|8[09)) [0-9]|349] \\d{7}$";
- /**
- 25 * Mainland China fixed and PHS
- 26 * Area code: 010,020,021,022,023,024,025,027,028,029
- 27 * Number: seven-bit or eight-bit
- 28 */
- //NSString * PHS = @ "^0 (10|2[0-5789]|\\d{3}) \\d{7,8}$";
- nspredicate *regextestmobile = [nspredicate predicatewithformat:@ "Self MATCHES%@", MOBILE];
- nspredicate *REGEXTESTCM = [nspredicate predicatewithformat:@ "Self MATCHES%@", CM];
- nspredicate *REGEXTESTCU = [nspredicate predicatewithformat:@ "Self MATCHES%@", CU];
- nspredicate *REGEXTESTCT = [nspredicate predicatewithformat:@ "Self MATCHES%@", CT];
- if ([Regextestmobile evaluatewithobject:mobilenum] = = YES)
- || ([regextestcm evaluatewithobject:mobilenum] = = YES)
- || ([REGEXTESTCT evaluatewithobject:mobilenum] = = YES)
- || ([Regextestcu evaluatewithobject:mobilenum] = = YES))
- {
- return YES;
- }
- Else
- {
- return NO;
- }
- }
- Restricted input of special characters, validity judgment of price amount
- #define Mydotnumbers @ "0123456789.\n"
- #define Mynumbers @ "0123456789\n"
- -(void) createtextfiled {
- TextField1_ = [[Uitextfield alloc] initwithframe:cgrectmake (0, 0, 20, 20)];
- TextField1_. Delegate = self ;
- [self addsubview:textfield1_];
- TextField2_ = [[Uitextfield alloc] initwithframe:cgrectmake (0, 0, 20, 20)];
- TextField2_. Delegate = self ;
- [self addsubview:textfield2_];
- TextField3_ = [[Uitextfield alloc] initwithframe:cgrectmake (0, 0, 20, 20)];
- TextField3_. Delegate = self ;
- [self addsubview:textfield3_];
- }
- -(void) Showmymessage: (nsstring*) Ainfo {
- Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "hint" message:ainfo Delegate: Self cancelbuttontitle:@ "OK" otherbuttontitles: nil, nil nil];
- [Alertview show];
- [Alertview release];
- }
- -(BOOL) TextField: (Uitextfield *) TextField shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string {
- Nscharacterset *cs;
- if ([TextField Isequal:textfield1_]) {
- CS = [[Nscharacterset charactersetwithcharactersinstring:mynumbers] Invertedset];
- nsstring *filtered = [[string Componentsseparatedbycharactersinset:cs] componentsjoinedbystring:@ "" ];
- BOOL basictest = [string isequaltostring:filtered];
- if (!basictest) {
- [self showmymessage:@ "Only enter numbers"];
- return NO;
- }
- }
- Else if ([TextField Isequal:textfield2_]) {
- CS = [[Nscharacterset charactersetwithcharactersinstring:mynumbers] Invertedset];
- nsstring *filtered = [[string Componentsseparatedbycharactersinset:cs] componentsjoinedbystring:@ "" ];
- BOOL basictest = [string isequaltostring:filtered];
- if (!basictest) {
- [self showmymessage:@ "Only enter numbers"];
- return NO;
- }
- }
- Else if ([TextField Isequal:textfield3_]) {
- Nsuinteger Ndotloc = [TextField. Text rangeofstring:@ "."] . Location;
- if (Nsnotfound = = Ndotloc && 0! = Range) {
- CS = [[Nscharacterset charactersetwithcharactersinstring:mydotnumbers] Invertedset];
- }
- else {
- CS = [[Nscharacterset charactersetwithcharactersinstring:mynumbers] Invertedset];
- }
- nsstring *filtered = [[string Componentsseparatedbycharactersinset:cs] componentsjoinedbystring:@ "" ];
- BOOL basictest = [string isequaltostring:filtered];
- if (!basictest) {
- [self showmymessage:@ "can only enter numbers and decimal points"];
- return NO;
- }
- if (nsnotfound! = Ndotloc && range. location > Ndotloc + 3) {
- [self showmymessage:@ "up to three digits after decimal point"];
- return NO;
- }
- }
- return YES;
Determine if the phone number and price entered are legal