How do I use RegExp to filter objects, including title, email, and name?
Title and name must contain only alphabetic characters. The email must be valid.
RegExp Patterns:
Email = /[a-zA-Z0-9.-]{1,}@[a-zA-Z.-]{2,}[.]{1}[a-zA-Z]{2,}/
Title & Name = /^[A-Za-z]+$/
If any email is invalid, store it in a separate variable and store the other objects in a different variable.
In JSON, if the first object's email is invalid, it should be stored in a separate variable.
items = [
{
title: "This is a title",
email: "test@test.com",
status: "confirmed"
},
{
title: "Another title",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0774686a626869624774686a62736f6e6e69605964686a">[email protected]</a>",
status: "pending"
},
{
title: "Just some text",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa979fba83958fd49995d48f91">[email protected]</a>",
status: "pending"
}
]