Validation

Email addresses

Email addresses checked against RFC 5322 and split into local part, domain and display name.

Version 1.0.0 · 2 functions · 1 crate

#forms#email#sign-up

Functions

What use email_address.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use email_valid, email_parts from email_address (Quillo 0.6).

email_valid(address: str) → bool

Whether address is a well-formed email address. (Whether it receives mail, only sending one tells.)

email_parts(address: str) → anyor an error

{ local, domain, display, address } of an address, Ada <ada@example.com> too; the domain in lower case.

Get it

$ quillo install email_address               # email_address.qwer into this folder$ quillo install email_address --example     # and its example, email_address.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/email_address.qwer$ curl -O https://quillolang.org/plugins/files/email_address.qwe

Then, in your program, all of it or only what you call:

main.qwe
use email_address.qweruse email_valid, email_parts from email_address      // Quillo 0.6: only these

It uses this crate, which cargo fetches the first time the plugin is built:

[dependencies]
email_address = "0.2"

Example

email_address.qwe
// Checking the address in a sign-up form.////   quillo run email_address.qwe      then open http://localhost:8080/check?email=ada@Example.COMuse "email_address.qwer"route GET /check ? { email: str } = email_valid(email) ? email_parts(email)? : { error: "That is not an email address" }route GET /samples = { good: email_valid("ada@example.com"), bad: email_valid("ada@@example"), named: email_parts("Ada Lovelace <ada@Example.com>")? }
$ quillo run email_address.qwe$ curl 'localhost:8080/check?email=ada@Example.COM'$ curl 'localhost:8080/samples'

Source

email_address.qwer
//! Email addresses checked against RFC 5322 and split into their parts, display names included.//! version: 1.0.0//!//! [dependencies]//! email_address = "0.2"use email_address::EmailAddress;use serde_json::{json, Value};use std::str::FromStr;/// Whether `address` is a well-formed email address. (Whether it receives mail, only sending one tells.)pub fn email_valid(address: &str) -> bool {    EmailAddress::is_valid(address.trim())}/// `{ local, domain, display, address }` of an address, `Ada <ada@example.com>` too; the domain in lower case.pub fn email_parts(address: &str) -> Result<Value, String> {    let e = EmailAddress::from_str(address.trim()).map_err(|e| e.to_string())?;    let domain = e.domain().to_lowercase();    Ok(json!({ "local": e.local_part(), "domain": domain, "display": e.display_part(), "address": format!("{}@{}", e.local_part(), domain) }))}
Thread
77Useful? Like it, or add to its thread below.

Thread 0 posts

On Email addresses: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.