Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:39:58+00:00 2026-06-18T03:39:58+00:00

I am trying to validate an IP address using core javascript. I would like

  • 0

I am trying to validate an IP address using core javascript. I would like to make sure that each IP address section value must be greater>100. But it is not working properly. Please find the following code for more details.

function testIP(){
            var ip=document.getElementById("ipaddress").value;
            var first= ip.substring(0,3);
            var second= ip.substring(4,7);
            var third= ip.substring(8,11);
            var fourth= ip.substring(12,15);
            var error=false;
            if(first){

                var ippart1 = 0+first;

                if(first<100){

                }
                else{
                    alert("Please enter a valid ip address.First part of ip address is incorrect"); 
                    error=true;
                }
            }
            else    
                error=true;
            if(second){

                var ippart2 = 0+second;

                if(ippart2<100){

                }
                else{
                    alert("Please enter a valid ip address.Second part of ip address is incorrect");
                    error=true;
                }
            }
            else    
                error=true;
            if(third){

                var ippart3 = 0+third;

                if(ippart3<100){

                }
                else{
                    alert("Please enter a valid ip address.Third part of ip address is incorrect"); 
                    error=true;
                }
            }
            else    
                error=true;
            if(fourth){

                var ippart4 = 0+fourth;
                if(ippart4<100){

                }
                else{
                    alert("Please enter a valid ip address.Forth part of ip address is incorrect");
                    error=true;
                }
            }
            else    
                error=true;
            if(error==true){

                return false;
            }
            else
                return true;

        }

I think the problem is in the string to integer conversion. I have also tried parseInt function. It is also not working. Please take a look at it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:39:59+00:00Added an answer on June 18, 2026 at 3:39 am

    First of all I would suggest to check if the address is valid using this function:

       function validate( value ) {
             RegE = /^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/  
             if(value.match(RegE))  
                alert('Valid IP');  
             else  
                alert('Invalid IP'); 
          }
    

    Then use parse int but with a good condition (> not <):

    if(parseInt(first)>100){
    
                    }
    

    Also consider refactoring your code 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to validate an e-mail address using javascript. The problem is the
I have an Address object that I am trying to validate data against using
I'm trying to validate that an email address is in the correct format by
Possible Duplicate: Validate email address in Javascript? I am trying to use this javascript
I'm trying to validate a simple XML file against an XML schema using the
I am trying to validate two checkboxes. One of them must be checked in
i am trying to validate someone else's code here and they are using the
I am trying to validate using jquery validation and the error messages displayed it
Hi I am using razor and trying to use regular expression to validate email
I'm trying to use Ben Keen's RSV Jquery plug-in to validate an e-mail address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.