How to implement a regex for password validation in Swift?

前端 未结 6 1487
刺人心
刺人心 2020-12-22 16:18

I want to implement a regex validaton for passwords in Swift? I have tried the following regex, but not successful

([(0-9)(A-Z)(!@#$%ˆ&*+-=<>)]+)([         


        
6条回答
  •  既然无缘
    2020-12-22 16:55

    try with this one for Password must be more than 6 characters, with at least one capital, numeric or special character

    ^.*(?=.{6,})(?=.*[A-Z])(?=.*[a-zA-Z])(?=.*\\d)|(?=.*[!#$%&? "]).*$

    ^ assert position at start of the string
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    (?=.{6,}) Positive Lookahead - Assert that the regex below can be matched
    .{6,} matches any character (except newline)
    Quantifier: {6,} Between 6 and unlimited times, as many times as possible, giving back as needed [greedy]
    (?=.*[A-Z]) Positive Lookahead - Assert that the regex below can be matched
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    [A-Z] match a single character present in the list below
    A-Z a single character in the range between A and Z (case sensitive)
    (?=.*[a-zA-Z]) Positive Lookahead - Assert that the regex below can be matched
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    [a-zA-Z] match a single character present in the list below
    a-z a single character in the range between a and z (case sensitive)
    A-Z a single character in the range between A and Z (case sensitive)
    (?=.*\\d) Positive Lookahead - Assert that the regex below can be matched
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    \d match a digit [0-9]
    2nd Alternative: (?=.*[!#$%&? "]).*$
    (?=.*[!#$%&? "]) Positive Lookahead - Assert that the regex below can be matched
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    [!#$%&? "] match a single character present in the list below
    !#$%&? " a single character in the list !#$%&? " literally (case sensitive)
    .* matches any character (except newline)
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    $ assert position at end of the string
    

    https://regex101.com/#javascript

    more this you can try ....

    Minimum 8 characters at least 1 Alphabet and 1 Number:

    "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"
    

    Minimum 8 characters at least 1 Alphabet, 1 Number and 1 Special Character:

    "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$"
    

    Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet and 1 Number:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$"
    

    Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[d$@$!%*?&#])[A-Za-z\\dd$@$!%*?&#]{8,}"
    

    Minimum 8 and Maximum 10 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character:

    "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?&#])[A-Za-z\\d$@$!%*?&#]{8,10}"
    

提交回复
热议问题