There will be many approaches to solve this problem, we will use regular expressions to solve this in this post.
First we will regular expression that satisfies given conditions, then we will match with the given inputs.
Condition 1: Mobile number must start with 7, 8 or 9, so we will write ^[789] or ^[7-9]
Checkout the sample outputs below
Please let me know if this program fails for any of your inputs, I will verify and update.
#HappyLearning #HappyTesting
First we will regular expression that satisfies given conditions, then we will match with the given inputs.
Condition 1: Mobile number must start with 7, 8 or 9, so we will write ^[789] or ^[7-9]
- ^ indicates starting of the number
- [789] or [7-9] indicates 7 or 8 or 9
So first digit condition is satisfied.
Condition 2: It must contain 10 digits, so we will write [0-9]{9}
- [0-9] indicates any number between 0 to 9 including 0,9
- {9} indicates it allows [0-9] 9 times. [0-9]{9} means any number between 0 and 9 (including 0,9) can repeat 9 times after first digit
So second condition also satisfied. ^[789][0-9]{9} will be the final regular expression. Checkout the below program, give multiple inputs and verify the output.
Please let me know if this program fails for any of your inputs, I will verify and update.
#HappyLearning #HappyTesting
I appreciate the admin of this blog and this concept is very comprehensive. Thank you!!!
ReplyDeleteCorporate Training in Chennai
Corporate Training institute in Chennai
Spark Training in Chennai
Oracle Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Oracle DBA Training in Chennai
Corporate Training in Chennai
Corporate Training institute in Chennai
Great Article
Deleteandroid based projects
Java Training in Chennai
FInal Year Project Centers in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Really helpful thanks................
ReplyDelete