java - password Regexp doesn't work when split up -
i cannot regexp checks if password has @ least 1 digit work. has been answered everywhere answers stop working if split up. example in working password validation if remove:
(?=.*[a-z])(?=.*[a-z])(?=.*[@#$%^&+=])
from
^(?=.*[0-9])(?=.*[a-z])(?=.*[a-z])(?=.*[@#$%^&+=])(?=\s+$).{8,}$
in order check presence of single digit, whole thing stops working
i'm new regular expressions, seems make sense doesn't, show me light if can.
i'm not sure mean the whole things stops working.
(?=.*[a-z])(?=.*[a-z])(?=.*[@#$%^&+=])
all above mandate that:
- a lower case letter must appear @ least once
- an upper-case letter must appear @ least once
- any of
@#$%^&+=
must appear @ least once
so, there no reason taking them out should break anything--they independent components.
there myriad ways check if string
contains number. how want check depends on specific requirements. method used in presented regex through positive-look ahead: ^(?=.*[0-9])
^ : begins with
.* : matches 0 or more non-newline characters
[0-9]: character class matches numbers [0,1,2,...,9]
?= positive ahead, in case says match iff there exists @ least 1 number
hope helped. can start off oracle's tutorial on regular expressions. after digest that, i'm sure you'll able find more advanced resources via google.
Comments
Post a Comment