How to validate an email address
Afficher commentaires plus anciens
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
Réponses (2)
pratik gautam
le 23 Juil 2020
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
le 11 Jan 2022
0 votes
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">
Catégories
En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!