Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With</p> <pre><code>password.length </code></pre> <p>you can ask for the length of a string. Compare that to your desired limits.</p> <p>With</p> <pre><code>- (BOOL)string:(NSString *)text matches:(NSString *)pattern { NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil]; NSArray *matches = [regex matchesInString:text options:0 range:NSMakeRange(0, text.length)]; return matches.count &gt; 0; } </code></pre> <p>you have a method that provides regex to strings (you can also implement this as a category to NSString).</p> <p>The first parameter will be your password, the second will be the pattern.</p> <p>I am not that good with regex, so there might be better solutions but this would be my way</p> <pre><code>NSString *password = @"iS_bhd97zAA!"; NSString *scPattern = @"[a-z]"; NSString *cPattern = @"[A-Z]"; NSString *sPattern = @"[!%&amp;\._;,]"; NSString *nPattern = @"[0-9]"; if (8 &lt;= password.length &amp;&amp; password.length &lt;= 15 &amp;&amp; [self string:password matches:scPattern] &amp;&amp; [self string:password matches:cPattern] &amp;&amp; [self string:password matches:sPattern] &amp;&amp; [self string:password matches:nPattern]) { NSLog(@"PW is valid"); } </code></pre> <p><strong>Hint</strong></p> <p>The regex for special characters is tricky because you need to escape some of the chars. Mine might be correct, but I am not absolutely sure.</p> <p>There is also a possiblility to do this in only one regex, but this looks scary imo</p> <p>This one</p> <pre><code> (?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$ </code></pre> <p>has everything except the special chars, maybe you want to add that yourself :D</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload