How to validate an email address

Please help me write a programme to determine if a string is a valid email address.
defining a valid email address as name@domain.tld where "name" can contain the characters a-z, A-Z, 0-9, _, and . (dot). And "domain" can contain the characters a-z, and -. "name" and "domain" must be non-empty. "tld" can be "com", "org", or "net".
Aim is to return true if valid, otherwise false

Risposte (2)

user_entry = "username@domain.com";
control = regexp(user_entry,'[a-z_]+@[a-z]+\.(com|net)')
if(numel(control)==1)
aa="worked"
else
aa="failed"
end
here you go, hope it might help someone else
rwanda mc
rwanda mc il 11 Gen 2022

0 voti

The fully RFC 822 compliant regex is inefficient and obscure for validate email address because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use.
If you use HTML5, use this code:
<input type="email" name="email" required placeholder="Enter a valid email address">

Categorie

Scopri di più su Argument Definitions in Centro assistenza e File Exchange

Richiesto:

il 19 Feb 2019

Risposto:

il 11 Gen 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by