How to validate an email address
Mostrar comentarios más antiguos
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
Respuestas (2)
pratik gautam
el 23 de Jul. de 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
el 11 de En. de 2022
0 votos
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">
Categorías
Más información sobre Argument Definitions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!