ios - 确认密码的正则表达式
<p><p>我的密码正则表达式是</p>
<pre><code>- (NSString *) getRegularExpression:(NSString *)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}$";
}
</code></pre>
<p>如何编写包含上述要求的确认密码正则表达式,它也等于我的密码字符串。谁能帮帮我?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在你的 shouldChangeCharactersInRange 中你可以这样做</p>
<pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newString = ;
NSString *expression = @"^$|^[^[:space:]]{6,20}$";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:expression
options:NSRegularExpressionCaseInsensitive
error:nil];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:newString
options:0
range:NSMakeRange(0, )];
if (numberOfMatches == 0)
return NO;
return YES;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 确认密码的正则表达式,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23403292/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23403292/
</a>
</p>
页:
[1]