I am trying to create a regular expression to validate a password-like field in my Google Form. The problem I am facing is that Google Form's regex validation does not support lookaheads. It gives a "Please enter a valid regular expression" error. So I am stuck with creating a regex without lookaheads.
Only following two conditions must be fulfilled for my password validation regex:
So, strings like password12, 12PASSWORD, pass12word, 12pasSWord12, pas12pas12pas12!!@@ etc all should be accepted by the regex.
I have currently tried using lookahead like the following expression which works well on other regex validation modules but gives an error on Google Form regex. Please look at this example 1
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,15}$
I tried to create my regex by using an IF clause like the following expression. Again this regex works well on other regex validations but gives an error in Google Form. Please see this example 2
\A(?>(?<char>[a-zA-Z])|(?<digit>[0-9])|.){8,}?((?(char)(?(digit)|(?!))|(?!)))
(([0-9]+[a-zA-Z]*){9,}[a-zA-Z]+)|(([a-zA-Z]+[0-9]*){9,}[0-2]+)
=> This only validates strings like password12 or 12password
([a-zA-Z]*[0-9]*[a-zA-Z][0-9][a-zA-Z]*[0-9]*){9,}
=> This only validates p1p2p3p4p5p6p7
Can you help me in creating a similar regex to the above 2 regex'es which will satisfy the two conditions required(length>8 and at least one alphabet and digit)?
I would appreciate any help I can get. Thanks!
Apparently there is no simple solution for this. Here is a solution which takes into consideration all the possible variations of the string.
.*([A-Za-z][0-9]......|[A-Za-z].[0-9].....|[A-Za-z]..[0-9]....|[A-Za-z]...[0-9]...|[A-Za-z]....[0-9]..|[A-Za-z].....[0-9].|[A-Za-z]......[0-9]|[0-9][A-Za-z]......|[0-9].[A-Za-z].....|[0-9]..[A-Za-z]....|[0-9]...[A-Za-z]...|[0-9]....[A-Za-z]..|[0-9].....[A-Za-z].|[0-9]......[A-Za-z]|.[A-Za-z][0-9].....|.[A-Za-z].[0-9]....|.[A-Za-z]..[0-9]...|.[A-Za-z]...[0-9]..|.[A-Za-z]....[0-9].|.[A-Za-z].....[0-9]|.[0-9][A-Za-z].....|.[0-9].[A-Za-z]....|.[0-9]..[A-Za-z]...|.[0-9]...[A-Za-z]..|.[0-9]....[A-Za-z].|.[0-9].....[A-Za-z]|..[A-Za-z][0-9]....|..[A-Za-z].[0-9]...|..[A-Za-z]..[0-9]..|..[A-Za-z]...[0-9].|..[A-Za-z]....[0-9]|..[0-9][A-Za-z]....|..[0-9].[A-Za-z]...|..[0-9]..[A-Za-z]..|..[0-9]...[A-Za-z].|..[0-9]....[A-Za-z]|...[A-Za-z][0-9]...|...[A-Za-z].[0-9]..|...[A-Za-z]..[0-9].|...[A-Za-z]...[0-9]|...[0-9][A-Za-z]...|...[0-9].[A-Za-z]..|...[0-9]..[A-Za-z].|...[0-9]...[A-Za-z]|....[A-Za-z][0-9]..|....[A-Za-z].[0-9].|....[A-Za-z]..[0-9]|....[0-9][A-Za-z]..|....[0-9].[A-Za-z].|....[0-9]..[A-Za-z]|.....[A-Za-z][0-9].|.....[A-Za-z].[0-9]|.....[0-9][A-Za-z].|.....[0-9].[A-Za-z]|......[A-Za-z][0-9]|......[0-9][A-Za-z]).*
Visit this to test it out: https://regexr.com/5pimr