5th Unit CSS
5th Unit CSS
A regular expression (regex) is a sequence of characters that forms a search pattern. It is mainly used
to match strings (text) in patterns or to validate the structure of data, such as email addresses, phone
numbers, or any other string format.
2. Construct regular expression for validating the phone number in following format only: (nnn)-
nnnn-nnnn OR nnn.nnnn.nnnn.
Here is the regular expression for validating the phone number in the given format:
^\(\d{3}\)-\d{4}-\d{4}$|^\d{3}\.\d{4}\.\d{4}$
Explanation:
• ^ and $ anchor the match to the beginning and end of the string, respectively.
• 3. Write a Java program that checks whether the string entered by the
user contains digits or not.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Check Digits</title>
</head>
<body>
<h2>Enter a string:</h2>
<p id="result"></p>
<script>
function checkDigits() {
if (result) {
} else {
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Rollover</title>
</head>
<body>
<script>
img.src = newSrc;
img.src = originalSrc;
</script>
</body>
</html>
Explanation:
• The onmouseover event changes the image source to the hover version, while the
onmouseout event resets it to the original image.
6. How will you specify the range of characters using a regular expression?
In regular expressions, ranges of characters are specified using square brackets []. For example:
•
7. Give the regular expression for matching digits and non-digits.
• Digits: \d or [0-9]
• Non-digits: \D or [^0-9]
1. lastIndex: Specifies the index at which to start the next match. It is used in exec() and test()
methods.
o Example: /abc/.lastIndex = 5;
2. global: A boolean value that indicates whether the g flag is set, meaning to search for all
matches in the string.
3. ignoreCase: A boolean value that indicates whether the i flag is set, meaning the search is
case-insensitive.
4. multiline: A boolean value that indicates whether the m flag is set, meaning that ^ and $
match the start and end of a line, not just the start and end of the string.
9. What is a frame?
A frame is a section of a web page that can display its own content. It allows a web page to
be divided into multiple sections that can load different content independently. Frames were
commonly used in earlier web designs but are now deprecated in favor of modern techniques
like CSS grid and flexbox.
10. Explain the <frameset> tag along with the attributes used in it.
The <frameset> tag is used to define a set of frames within a web page. It replaces the <body> tag
when using frames. The common attributes are:
• frameborder: Specifies whether or not to display a border around the frames (0 = no border,
1 = with border).
Example:-
<frame src="frame1.html">
<frame src="frame2.html">
</frameset>
11. Write a JavaScript to display frames without borders.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
</frameset>
</body>
</html>
12. Write a JavaScript to change the contents of one frame from another.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
</frameset>
<script>
function changeContent() {
window.frames['frame2'].document.location = 'newContent.html';
</script>
</body>
</html>
13. Write JavaScript to change the label of a button element present in frame2.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
</frameset>
<script>
function changeButtonLabel() {
</script>
</body>
</html>
A rollover effect refers to a visual change in an element when the user moves the mouse over it,
such as changing the color or image of a button or link.
15. What are the methods used most commonly during the rollover?
• onmouseover: Triggered