Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2275

Administration Joomla! 5.x • Re: client side email validation not work

$
0
0
Hi @zubata,

You're right.
Your regex works fine. I've tried it. https://regex101.com/r/bp1fR1/1

The reason mail@mail passes the browser's built-in type="email" validation is that the HTML5 email validation is not very strict. It simply checks for the @ symbol, a valid domain name (text after @), and at least one character after the final dot in the domain.

In Joomla, you can use a plugin to hook into the form submission process (e.g., onUserBeforeSave) to validate the email field.

Code:

public function onUserBeforeSave($user, $isNew, $data){    $email = $data['email'];    if (!filter_var($email, FILTER_VALIDATE_EMAIL) || !preg_match('/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i', $email)) {        throw new RuntimeException('Please provide a valid email address.');    }}

Statistics: Posted by Yiannistaos — Sat Jan 04, 2025 5:59 pm



Viewing all articles
Browse latest Browse all 2275

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>