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 6883785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:25:34+00:00 2026-05-27T05:25:34+00:00

Im trying to validate the input to see if it a valid IP address(could

  • 0

Im trying to validate the input to see if it a valid IP address(could be a partial one).

Acceptable input : 172, 172.112, 172.112.113, 172.112.113.114

Unacceptable input: 1724,172.11113 etc etc

Heres a function that I created to check it (however it validates unacceptable input like 1724 which I cant seem to fix..please help)

def ipcheck(ip):
    ippattern_str = '(([1-2]?[\d]{1,2}\.?){0,1}(\.[1-2]?[\d]{1,2}){0,1}(\.[1-2]?[\d]{1,2}\.){0,1}(([1-2]?[\d]{1,2}[\D\W]*)'
    ippattern = re.compile(ippattern_str)
    # ippattern is now used to call match, passing only the ip string
    global matchip
    matchip = ippattern.match(ip)
    return matchip


ip = sys.argv[1]
ipcheck(ip)

print matchip

I feel like maybe I need to use anchors properly? Ive tried everything to my best knowledge, any help would be appreciated.

  • 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-05-27T05:25:35+00:00Added an answer on May 27, 2026 at 5:25 am

    This regex would do the trick:

    ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){0,3}$
    

    It ensures that the given numbers are in the correct range (0-255) and can have 1-4 parts.

    You can see it in action here: http://regexr.com?2va3j

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

Sidebar

Related Questions

I’m trying to validate input by using egrep and regex.Here is the line from
I'm trying to validate user input, which is just comma separated numbers. I'd like
I'm trying to validate a input field with the JQuery validation plugin. The numeric
I am trying to validate an input field when it loses focus and re-focus
I am trying to validate a text input when it loses focus. I would
I'm trying to practice writing better code, so I wanted to validate my input
I'm trying to validate user input by using the QString::toDouble() function. The documentation says
I'm trying to create a registration form and validate input fields using javascript, but
I'm trying to validate that the input a user gives my program via gets
Trying to validate a comma-separated email list in the textbox with asp:RegularExpressionValidator , see

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.