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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:38:18+00:00 2026-05-23T19:38:18+00:00

Is there a way to check a valid host:port combination using regex and php?

  • 0

Is there a way to check a valid host:port combination using regex and php?

The regular expression has to make sure that:

  • host is a valid IP (containing four 1-3 digit numbers separated by 3 dots, number in range of 1-255)
  • there is a delimiter :
  • port is a valid number between 0 and 65535
  • nothing else is allowed

Examples of valid combinations:

  1. 95.241.1.5:5423

  2. 2.8.5.2:65532

Examples of INvalid combinations:

  1. 1.2345.12.1:5441

  2. 15.852.32.455:151896841

  3. 65.112.15.32:48trololo

  • 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-23T19:38:19+00:00Added an answer on May 23, 2026 at 7:38 pm
    ^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]):(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])$
    

    should work, but it’s not pretty trying to match numbers with regexes…

    In verbose format, a bit more readable:

    ^
    (?:
     (?:
      25[0-5]|        # 250-255
      2[0-4][0-9]|    # 200-249
      1[0-9][0-9]|    # 100-199
      [1-9]?[0-9]     # 0-99
     )  
     \.               # .
    ){3}              # three times, last segment follows (no dot)
    (?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])
    :                 # :
    (?:
     6553[0-5]|       # 65530-65535
     655[0-2][0-9]|   # 65500-65529
     65[0-4][0-9]{2}| # 65000-65499
     6[0-4][0-9]{3}|  # 60000-64999
     [1-5][0-9]{4}|   # 10000-59999
     [1-9][0-9]{1,3}| # 10-9999
     [0-9]            # 0-9
    )
    $
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to check whether a regular expression represents a valid URL
Is there an easy way to check an email address is valid using Ajax?
Is there a way to check if a tag is valid html tag and
Is there a way to check to see if a date/time is valid you
Is there any way to check whether a file is locked without using a
Is there a way to check if a file has been opened by ReWrite
Is there a way to check if a ValidationSummary control has its IsValid property
I need to check if a string is a valid regex. Is there any
Is there any way to check that a variable is a valid JSON string
Is there any easy way to check whether a path is valid? The file

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.