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