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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:49:26+00:00 2026-06-10T10:49:26+00:00

A page I’ve made allows users to submit IP’s (All are IPv4, not IPv6)

  • 0

A page I’ve made allows users to submit IP’s (All are IPv4, not IPv6) with %’s as wildcards (e.g. 192.168.1.%). They can also submit full IP’s without wildcards. The IP’s are posted via a regular HTML form input, so something like <input name=\"ip\" maxlength=\"15\"/>.

Essentially, I just need to check that IP’s only contain numbers, dots, and percent signs (two at most). I’m not really concerned with people putting in numbers that are greater than 255, but I don’t want them to be able to put more than three numbers per every dot.

I don’t know regex much at all, so I don’t even know where to begin. I know that [0-9] would only allow numbers 0-9, but that’s probably not going to help much. Should I be splitting the $_POST[‘ip’] variable into parts using dots as the delimiter, then running regex stuff on each part? It’s probably more efficient just to run it all at once.

  • 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-10T10:49:27+00:00Added an answer on June 10, 2026 at 10:49 am

    While you could do this with a Regular Expression, I believe it would be complex and a more straightforward solution would be a combination of String functions and filter_var().

    Pseudo Code

    • substr_count() the wildcards to ensure max of 2
    • str_replace() wildcards with a safe digit, say 50
    • Use filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)

    If any of these fail, you have a bad IP. In the interest of teaching you to fish, I’ll leave the code up to you.

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

Sidebar

Related Questions

page.xml.php will not show any output, in firebug I can see the get response
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Page speed suggests to give image height and width for the images , can
This page describes all steps to edit RC: http://msdn.microsoft.com/en-us/library/dd456813.aspx Those are easy steps, pretty
The page i have is very simple, but all of the links are loaded
Page not found (404) Request Method: GET Request URL: http://beta.mysite.com/admin/filebrowser/ The requested admin page
Page works fine in chrome, and IE 9 compatibility mode but not in actual
page.xml contains: <default translate=label module=page> <label>All Pages</label> <reference name=root> <action method=addBodyClass><className>testing</className></action> </reference> Yet it's
Page my question is referring to: http://raphaeljs.com/australia.html Can some kind individual please tell me
Page of the application with the TextBlock and Button, also involved .txt document with

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.