Basically I want to create an effect like the one you get with required attributes:

But since I'm not able to use something like type="email", because my patterns differ (and sometimes the input is used to add elements to an array), I want to check the validity manually via JavaScript and, if the inputted data isn't right, report it to the user as shown above.
Any ideas how to do it are highly appreciated!