Question

Write a regex (Example: [Hh]ello means Hello or hello) that could recognize any web page address...

Write a regex (Example: [Hh]ello means Hello or hello) that could recognize any web page address (URL).

Requirements:

1. "http://", or "https://", is optional, and one of them may appear once, or not.

2. there is no need for a web page address to have "www"

3. the top level domain must be one of the available domains: "com", "org", "net", or "edu"

4. at least one word (word = at least 2 characters) must be at the front of the top level domain name, and they must be separated by "."

For instance, "ab.com", "ab.cd.efg.com", or "https://ab.com", or "abc.org", etc., they are all valid, but "a.com" is not valid

5. After the top level domain name, there may be zero, one, or more subcategories specified. If there is one subcategory, then symbol "/" must be used to separate it with the top level domain name or other subcategories.

For instance, "ab.com/xyz", "abc.def.net/xyz/xxx", "abc.edu/aaa/bbb.html", etc., are all valid

6. a web page address may end with symbol "/". That is, "abc.com", "abc.com/", or "abc.com/xyz/" are all valid.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Prgrame:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>url Validator</title>

<link rel="stylesheet" href="regex.css">

<script src="regex.js"></script>

</head>

<body>

<main>

<h1>Validate URL </h1>

<label for="url">URL</label>

<input type="text" id="url"><br>

<label>&nbsp;</label>

<input type="button" id="validate" value="Validate"><br>

<label>&nbsp;</label>

<span id="message">&nbsp;</span>

</main>

</body>

</html>

regex.css

body {
font-family: Arial, Helvetica, sans-serif;
background-color: white;
margin: 0 auto;
width: 400px;
border: 3px solid blue;
padding: 0 2em 1em;
}
h1 {
color: blue;
}
label {
float: left;
width: 11em;
text-align: right;
padding-bottom: .5em;
}
input {
margin-left: 1em;
margin-bottom: .5em;
}
#message {
margin-left: 1em;
color: red;
}

regex.js

"use strict";
var $ = function(id) { return document.getElementById(id); };

var validateurl = function() {
var url = $("url").value;
var pattern = /(http(s)?://.)?(www.)?[-a-zA-Z0-9@:%._+~#=]{2,256}.[a-z]{2,6}([-a-zA-Z0-9@:%_+.~#?&//=]*)/g; // 999-999-9999
var isValid = pattern.test(url);
$("message").firstChild.nodeValue = (isValid) ? "Valid URL number" : "Invalid URL ";
};

window.onload = function() {
$("validate").onclick = validateurl;
};

output:

Add a comment
Know the answer?
Add Answer to:
Write a regex (Example: [Hh]ello means Hello or hello) that could recognize any web page address...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JUDY'S HTML TUTORIAL MENU CREATING YOUR FIRST WEB PAGE The best way to make a web...

    JUDY'S HTML TUTORIAL MENU CREATING YOUR FIRST WEB PAGE The best way to make a web page is to just dive right in. Open Notepad. To open notepad in Windows, click the windows icon in the lower left corner of the screen and then type "notepad." Notepad is a text editor. Other text editors you may consider are TextPad, Sublime Text, or NotePad++. Do not use Word or WordPad; they are word processors. If you are using an Apple computer...

  • This assignment is due 2/25 and is worth 50 points Opinion Paper and Comparative Critique: Print...

    This assignment is due 2/25 and is worth 50 points Opinion Paper and Comparative Critique: Print Media and Website Information Objective: This assignment will test your ability to critically analyze popular media nutrition information, according to its content, whether you think the information is valid and/or accurate based on the principles you are learning from the course. This will help you to integrate and apply knowledge from class materials and/or relevant personal experiences. ______________________________________________________________________________________________________ Instructions: Note: This is one assignment...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT