Lex code for password validation

Lex is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lex in the C programming language.

Problem: We have to validate password.
A password is correct if it contains:

  1. Atleast 1 uppercase character
  2. Atleast 1 lowercase character
  3. Atleast 1 digit
  4. Atleast 1 special character
  5. Minimum 8 characters


Input: Geeksforgeeks

Input: Geeks@12
Output: VALID 

Note: The words can consist of lowercase characters, uppercase characters and digits.

Below is the implementation to count the number of words.





    int a = 0, b=0, c=0, d=0, l=0; 
[a-z]    {a++;l++;}
[A-Z]    {b++;l++;}
[0-9]    {c++;l++;}
[$&+, :;=?@#|'<>.-^*()%!] {d++;l++;}
.  ;
int yywrap(void){} 
int main() 
    // The function that starts the analysis 
      if(a>0 && b>0 && c>0 && d>0 && l>=8)
    return 0; 



Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.