All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

HTML Input Pattern Numbers Only

Last Updated : Jul 1, 2023

HTML Input Pattern Numbers Only

In this tutorial we will show you the solution of HTML input pattern numbers only, in HTML we all know that there is an input tag that is used under form tag.

Whereas form tag is used to receive data from the user as feedback forms and surveys etc. Hence, there is also need of numbers sometimes that we want to get as input from user.

Like in form of age, mobile number and also in many other ways. Or also many times user enters or type wrong number by mistake and we did not want that feedback which is wrong. So, we use number patterns.

Step By Step Guide On HTML Input Pattern Numbers Only :-

As, there are many ways with the help of which you are able to apply conditions on input tag. We can use jQuery and JavaScript libraries also.

Hence, these are seems to be very complex, so to avoid this we today are here and want to show you that how you are able to apply this condition with the help of html only.

And this can be done with the help of html input pattern numbers. Which we describe in below points.

Here, below we give you a code in html, we hope that you are able to understand what we do here.

<!DOCTYPE html>
      <html>
        <head>
          <title> Title of the document<title>
   </head>
<body>
   <form action="demo10/secondbusiness.html" method="get">
        <label for="">
            Please enter your enter your mobile number
        </label>
        <input type="tel" name="phone" id="phone" placeholder="0123-456-789" pattern="[0-9]{4}-[0-9]{3}-[0-9]{3}">
        <br><br>
        <label for="">
            please enter your telephone number
        </label>
        <input type="tel" name="nmbr" id="nmbr" pattern="[0-9]{4}-[0-9]{6}" placeholder="0161-123456">
<label for="">
            please enter your age in numbers which must be between 0-99
        </label>
        <input type="number" name="nmbrone" id="nmbrone" pattern="[0-9]{2}" placeholder="18">
        <input type="submit">
    </form>
</body>
      </html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Thirdly, <body> tag is used to define the webpage body. All the contents to show on website are written here. In body, here we show you three examples.
  5. The first is of mobile number, next is of telephone number and last is of age.
  6. In all of them, we use patterns, except this most of same. The patterns are used where you want to apply condition on numbers.
  7. The first one used in patterns is square brackets, which are used to describe range, which is between 0-9, and other in square bracket, we use these for range.
  8. Like how many digits a user have to enter and in which pattern. We hope you understand this article properly.
  9. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

In conclusion, here we want to say that with the help of this article you are able to apply patterns only any input type like which may be a number or may be telephone.

Also, we show you how to use patterns in telephones with proper understandability. I hope this tutorial on HTML input pattern numbers only helps you.

Author Image About Riya

A recent graduate with a Bachelor of Technology (B.Tech) in Computer Science from India. She is passionate about leveraging technology to solve real-world problems. With a strong foundation and experience in programming languages such as Python, Django, HTML, CSS, and JavaScript, java, php and have honed her skills through hands-on projects and coursework.

Follow Riya On Linkedin 🡪