Sunday, January 27, 2019

Java Program 2: Verify the given mobile number contains 10 digits and starts with 7, 8 or 9 only

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]
  • ^ 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.

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


  1. Replies
    1. Great Article
      android 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

  2. Really helpful thanks................


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...