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>
<html>
    <header>
       <title>Phone number validation in html</title>
    </header>
    <div id="wrapper">
        <form>
            <label>Number</label>
            <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>
        </form>
    </div>
</html>

Here is the result.

 

Submit a Comment

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

Subscribe

Select Categories