Skip to content
Related Articles

Related Articles

How to check validation of IP Address in jQuery ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 12 May, 2021
View Discussion
Improve Article
Save Article

In this article, we will find how to validate the IP Address using jQuery.

IP Address: Every computer connected to the Internet is identifiable by a unique string, which is known as its Internet Protocol (IP) address. It consists of four numbers (each between 0 and 255) separated by dots. The format of an IP address can be written as four decimal numbers separated by dots, each number can be written from 0 to 255. An example of valid IP address is as follows.


We can check whether the IP Address is valid or not using regex (regular expression) easily. Let us take an example to understand how it works. Now let us first discuss how regex can be used to validate IP addresses. The regular expression that would be used to verify IP address specifically ip4 address is as below.


  • In the above expression [0-9] indicates any number from 0 to 9.
  •  | indicates conditional “or“.
  • [1-9][0-9] indicates any number from 10 to 99.
  • 1[0-9]{2} means 1[0-9][0-9] which indicates any number starting from 100 to 199.
  • 2[0-4][0-9] indicates any number starting from 200 to 249.
  • 25[0-5] indicates any number starting from 250 to 255.
  • {3} indicates that the pattern occurs three times.



<!DOCTYPE html>
<html lang="en">
    <script src=
    <script src=
  <body style="text-align: center">
    <h2>Jquery IP Address Checker</h2>
      <div class="form-group row">
        <label for="inputPassword"
               class="col-sm-2 col-form-label">
          Enter IP Address:
        <div class="col-sm-8">
            placeholder="IP Address"
      <button type="submit" id="submit" 
              class="btn btn-primary">
      <p style="color: green" id="demo"></p>
      $(document).ready(function () {
        $("#submit").click(function (value) {
          // Using Regex expression for validating IPv4
          var ipaddress =
          var content = $("#ip").val();
          if (ipaddress.test(content)) {
            $("#demo").html("Ipaddress is Valid");
          } else {
            $("#demo").html("Ipaddress is invalid");

Output: The following result is shown on entering a valid and invalid IP Address.


IP address validation output


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!