Regular Expression for password in iPhone

后端 未结 2 1311
北海茫月
北海茫月 2020-12-21 19:14

I am pretty much weak in creating Regular Expression. So i am here.

I need a regular expression satisfying the following.

NSString *nameRegex =@\"My          


        
相关标签:
2条回答
  • 2020-12-21 19:37

    As a non-regex expert, I would solve this by splitting up the criteria into separate tests which can then be easier understood and changed, ie multiple if conditions. I believe this cannot be done with a single regex, at least not in an understandable fashion :)

    0 讨论(0)
  • 2020-12-21 19:52

    Here's how you do it !

    /^[a-zA-Z0-9]{7,32}$/

    Don't forget the "beginning to end" markers.

    For the record, if you want it the string to definitely include both letters and digits, there is no way to do that with one regex. (In fact, mathematically you could do it, but the regex would be enormous.)

    Simply run the above check, and THEN ALSO CHECK that it contains a letter: /[a-zA-Z]/

    And THEN ALSO TEST that it contains a digit: /[0-9]/

    That's the easiest way.

    0 讨论(0)
提交回复
热议问题