我的密码正则表达式是
- (NSString *) getRegularExpressionNSString *)extraWords
{
/*
* ^$ Empty string
* | Or
* ^ Start of a string
* [] Explicit set of characters to match
* ^[:space:] Matches any non-white-space character - equivalent to \S
* {6,30} 6-20 characters
* $ End of a string
*/
return @"^$|^[^[:space:]]{6,20}$";
}
如何编写包含上述要求的确认密码正则表达式,它也等于我的密码字符串。谁能帮帮我?
Best Answer-推荐答案 strong>
在你的 shouldChangeCharactersInRange 中你可以这样做
- (BOOL)textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)string
{
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSString *expression = @"^$|^[^[:space:]]{6,20}$";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:expression
options:NSRegularExpressionCaseInsensitive
error:nil];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:newString
options:0
range:NSMakeRange(0, [newString length])];
if (numberOfMatches == 0)
return NO;
return YES;
}
关于ios - 确认密码的正则表达式,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23403292/
|