How To Set Phone Number Validation Using Regex In Simple HTML Form

In this article, We will learn how to set phone number validation using regex in simple HTML form.
Step-1: Creat form in HTML and use pattern in input.

<!DOCTYPE html>
       <title>Phone number validation in html</title>
    <div id="wrapper">
            <input type="text" name="number" pattern="^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$" placeholder="+1 (416) 555-1212" required>
            <button type="submit">Submit</button>

Here is the result.


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories