0% found this document useful (0 votes)
2 views3 pages

JS Regex & Events

The document provides an overview of JavaScript Regular Expressions (Regex) and event handling. It covers the basics of Regex, including literals, constructors, flags, common patterns, and applications in form validation, search and replace, and IP address extraction. Additionally, it outlines various event handling techniques such as button clicks, mouse events, key presses, form submissions, and change events.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

JS Regex & Events

The document provides an overview of JavaScript Regular Expressions (Regex) and event handling. It covers the basics of Regex, including literals, constructors, flags, common patterns, and applications in form validation, search and replace, and IP address extraction. Additionally, it outlines various event handling techniques such as button clicks, mouse events, key presses, form submissions, and change events.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11/14/25, 12:18 PM JS Regex & Events

JavaScript Regular Expressions & Event


Handling

Regular Expressions
A sequence of characters that forms a search pattern.

1. Regex Literal

/hello/[Link]("Hello World") = true

2. RegExp Constructor

new RegExp("hello", "i").test("Hello World") = true

Regex Flags
Global Flag (g)

"cat, cat, dog".match(/cat/g) = [cat,cat]

Multiline Flag (m)

Multiline match: [second]

Common Regex Patterns


^ start, $ end, \d digit, \s whitespace, + one or more, {n} exactly n times, [abc] character set

Form Validation with Regex


1. Email Validation

[Link]:5500/[Link] 1/3
11/14/25, 12:18 PM JS Regex & Events

user@[Link] Validate Email

2. Phone Number Validation

9876543210 Validate Phone

3. Name Validation (Alphabets Only)

John123 Validate Name

Search and Replace


I love JavaScript and JavaScript is fun!

Replace Spaces with - Extract Numbers

IP Address Extraction

Extract IP from Log

Event Handling
1. Button Click Event

Click Me

2. Mouse Events
Hover over
me!

[Link]:5500/[Link] 2/3
11/14/25, 12:18 PM JS Regex & Events

3. Key Press Event

Type something

4. Form Submit Event

Enter name Submit

5. Change Event

Select a color

[Link]:5500/[Link] 3/3

You might also like