How to Write Phone Number Validation Test Cases

Phone Numbers

In this how-to, we will walk through how to write sample test phone number validation test cases. Many applications collect your mobile number. Some examples of applications include purchasing on eCommerce websites, scheduling an appointment, or waiting for a call-back to your mobile number. As a result, creating sample test cases for phone number field applies to all testers. Follow along with this how-to and finish your application’s first test case by creating your account in our test case management tool. Before starting our test case, we need to define the Acceptance Criteria.

What are the Acceptance Criteria for phone number field test cases?

As discussed in our requirements post, we must have functional requirements. So let’s go ahead and define them as such:

Description: “User must be able to enter their mobile phone number while registering their account.”

Person entering mobile number

Abbreviated Acceptance Criteria:

  • Validate the phone number can be entered depending on the country code.
  • Validate error messages are thrown when invalid data is entered.

What are the Test Cases for Phone Number Validation?

  1. Validate the mobile number field enforces the correct number of characters for the region you are testing. For example a 10 digit mobile number:
    1. Must accept 10 digits ie. “5152133212”
    2. Must throw an error with less than 10 digits ie. “515213321”
    3. Must not accept more than 10 digits. ie. 51523235321
  2. Validate the formattingof the mobile number, based on business requirements. Examples of potential formats:
    1. ###-###-####
    2. ###.###.####
    3. (###)###-####
  3. Validate blank input space between the mobile number field is not accepted. Ex: 51532 12343
  4. Validate the mobile number input text box accepts copy and paste input.
  5. Based on requirements, verify the mobile number field is mandatory field or not.
  6. Validate error messages are thrown if validation issues exist. Examples might include:
    1. Mobile number field entered with fewer characters than expected.
    2. Mobile number field entered with too many characters (if testing through the API, or the input field does not stop at a certain number).
    3. Not entering a mobile number field.
    4. Mobile number field has a special character.
  7. Validate a placeholder text exists for the mobile number input text box.
  8. Validate the correct mobile number data is persisted in the database when the Save or Next button is clicked.
  9. Validate the form can be saved by pressing the enter button with a valid mobile number.
  10. Depending on requirements, verify the country code and flag are displayed in the mobile number field.

Keep in mind there are diminishing returns to testing, and developers should be using a thoroughly tested library for some of this functionality. Here are some tests some folks might be tempted to run, but are not needed because they are using inbuilt operating system functionality not specific to the application.

  1. Validate the text box accepts 10 zero numbers in the mobile number field.
  2. Validate the mobile number field text box by entering 10 blank input spaces.
  3. Validate the mobile number text box does not accept alpha characters.
  4. Validate error is thrown when no value is entered in the mobile number field.
  5. Validate entering a special character in the mobile number field throws an error.
  6. Validate entering a 0 at the initial space of the mobile number field.
  7. Validate a specific error message is thrown when the user saves the form without a mobile number in the text box (assuming requirements state the field is mandatory).

The best thing you can do as a tester is discuss, with the developer, what the mobile number library code is doing and what it is not doing. Another quick sanity check is to review your developer’s code check-in for the story you are working on. Doing so can help target your testing efforts when testing the mobile number.

Writing Sample Test Cases

In this future section, we will go into detail on how to write valid mobile number test scenarios.

AccelaTest - API Testing Simplified

Conclusion for Test Cases for Phone Number Field

AccelaTest is a free test case management tool packed with features that most other testing tools charge a lot of money for. Get your free account now and create your test cases.

ACCELATEST UNIVERSITY
Hello there
Do you want to learn the Software Testing techniques, tips, and tricks that have led to a stable, high-paying job and prevented embarrassing multimillion-dollar bugs?