Software Testing / Grey Box Testing

Pattern Testing Techniques

Pattern Testing is a method used to identify and test repeating patterns within a system. In this tutorial, you will learn about different Pattern Testing techniques and how to im…

Tutorial 2 of 5 5 resources in this section

Section overview

5 resources

Grey Box Testing is a software testing method which is a combination of Black Box Testing method and White Box Testing method.

Pattern Testing Techniques Tutorial

1. Introduction

Brief Explanation of the Tutorial's Goal

This tutorial aims to provide an understanding of Pattern Testing techniques and their implementation in HTML.

What Will the User Learn

By the end of this tutorial, you will be able to identify and test repeating patterns within a system using various Pattern Testing techniques.

Prerequisites

You should have a basic understanding of HTML and web development concepts.

2. Step-by-Step Guide

Pattern Testing, also known as Pattern Matching, is the process of checking a given sequence of tokens for the presence of the constituents of some pattern.

Regular Expressions

One common way of pattern testing in HTML is using Regular Expressions. Regular expressions are sequences of characters that form a search pattern. This pattern can be used to match, locate, and manage text.

Here's an example of a simple regular expression:

/^Hello World$/

In this example, ^ asserts start of a line, Hello World is the pattern to match, and $ asserts end of a line.

HTML5 Pattern Attribute

HTML5 introduced the pattern attribute for the input element. The pattern attribute works with text-based input types: text, search, url, tel, email, and password.

Here's an example:

<input type="text" id="username" pattern="[a-zA-Z0-9]{5,12}" title="Username should only contain letters and numbers and be 5-12 characters long.">

In this example, the pattern attribute is used to enforce specific rules for the input field.

Best Practices and Tips

  • Use regular expressions sparingly. They can be difficult to read and maintain.
  • Be aware of cross-browser compatibility issues with the pattern attribute.

3. Code Examples

Example 1: Regular Expression

<script>
var str = "Hello World!";
var patt = new RegExp("^Hello World$");
var res = patt.test(str);
document.getElementById("demo").innerHTML = res;
</script>

In this example, we are testing if the string "Hello World!" matches the pattern "^Hello World$". The result (true or false) is displayed in an element with id="demo".

Example 2: Pattern Attribute

<form>
  <input type="text" name="username" pattern="[a-zA-Z]{3,}" title="Three or more letters">
  <input type="submit">
</form>

In this example, the pattern attribute is used to require that an input field must have more than 2 letters.

4. Summary

In this tutorial, we learned about Pattern Testing techniques and how to implement them in HTML. We discussed regular expressions and the pattern attribute in HTML5.

5. Practice Exercises

  1. Create a regular expression that matches an email address.
<script>
var str = "test@example.com";
var patt = new RegExp("^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$");
var res = patt.test(str);
document.getElementById("demo").innerHTML = res;
</script>

In this example, we are testing if the string "test@example.com" matches the pattern of an email address.

  1. Use the pattern attribute to require that a password field must contain at least one number, one uppercase letter, one lowercase letter, and be at least 8 characters long.
<form>
  <input type="password" name="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters">
  <input type="submit">
</form>

In this example, the pattern attribute is used to enforce specific rules for the password field.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Case Converter

Convert text to uppercase, lowercase, sentence case, or title case.

Use tool

MD5/SHA Hash Generator

Generate MD5, SHA-1, SHA-256, or SHA-512 hashes.

Use tool

Word Counter

Count words, characters, sentences, and paragraphs in real-time.

Use tool

Word to PDF Converter

Easily convert Word documents to PDFs.

Use tool

Markdown to HTML Converter

Convert Markdown to clean HTML.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help