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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:03:17+00:00 2026-05-27T19:03:17+00:00

I have implemented a function to validate .edu domains. This is how I am

  • 0

I have implemented a function to validate .edu domains. This is how I am doing it:

if( preg_match('/edu/', $matches[0])==FALSE )
    return FALSE;
return TRUE;

Now I want to skip those urls as well that point to some documents such as .pdf and .doc.

For this, the following code should have worked but is not:

if( preg_match('/edu/', $matches[0])==FALSE || preg_match('/pdf/i', $matches[0])!=FALSE || preg_match('/doc/i', $matches[0]!=FALSE))
        return FALSE;
return TRUE;

Where am I wrong in this regard?
Moreover, how will I implement preg_match in such a way that it has a list of document types to check in a url string. If a certain type of document is found, it should return false. In other words, I want to provide a list (an array maybe) of various document types as $pattern to find in a url.

Note:
matches[0] contains the whole url string.
eg: http://www.nust.edu.pk/Documents/pdf/NNBS_Form.pdf

The code for the function:

public function validateEduDomain($url) {
    // get host name from URL
    preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
    $host = $matches[1];

    // get last two segments of host name
    preg_match('/[^.]+\.[^.]+$/', $host, $matches);

    if( preg_match('/edu/', $matches[0])!=FALSE && (preg_match('/pdf/i', $matches[0])==FALSE || preg_match('/doc/i', $matches[0]==FALSE)))      
        return TRUE;
    return FALSE;
}
  • 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-27T19:03:18+00:00Added an answer on May 27, 2026 at 7:03 pm

    I wonder why are you making everything so complicated, and also noticed you have $$matches[0] instead of $matches[0]. The regexes you want is:

    if( preg_match('/^https?:\/\/[A-Za-z]+[A-Za-z0-9\.-]+\.edu/i', $matches[0]) && !preg_match('/\.(pdf)|(doc)$/i', $matches[0]) ) {
        // do something here...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return
I have implemented each function like this in JS: Object.prototype.each = function(fn){ for (var
I have implemented a curry function this way: function curry (fn) { var slice
I have implemented a function to do this already, but I don't like the
If I have a function foo() that windows has implemented in kernel32.dll and it
I have this class class Validator implements iValidation{ protected $_fields, $_errors; public function __construct($fields){
I am working on a winforms application. I have a function to validate the
I have a form implemented from hook_form called simplequiz_form() I want to access its
I have implemented a function TraverseStringClockwise which takes a comma separated string of integers,
I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is

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.