Lex program to check valid Mobile Number
Problem: Write a Lex Program to check valid Mobile Number.
Explanation:
FLEX (Fast Lexical Analyzer Generator) is a tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The function yylex() is the main flex function which runs the Rule Section.
Examples:
Input: 7017175023 Output: Mobile Number Valid Input: 0001112223 Output: Mobile Number Invalid
Implementation:
/* Lex Program to check valid Mobile Number */ %{ /* Definition section */%} /* Rule Section */%% [1-9][0-9]{9} {printf("\nMobile Number Valid\n");} .+ {printf("\nMobile Number Invalid\n");} %% // driver code int main() { printf("\nEnter Mobile Number : "); yylex(); printf("\n"); return 0; } |
Output:

Recommended Posts:
- Lex Program to check valid email
- Lex program to check if a Date is valid or not
- Lex Program For checking a valid URL
- Lex Program to accept a valid integer and float value
- Lex program to check whether given number is armstrong number or not
- Lex program to check whether a given number is even or odd
- Lex Program to check whether a number is Prime or Not
- Lex program to check whether input number is odd or even
- Lex program to recognize valid arithmetic expression and identify the identifiers and operators
- YACC program to implement a Calculator and recognize a valid Arithmetic expression
- Lex program to check whether the input is digit or not
- Lex program to check perfect numbers
- Lex program to check whether given string is Palindrome or Not
- C program to check syntax of 'for' loop
- YACC program to check whether given string is Palindrome or not
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.



