Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Structural Email Format Validation
Validate email address structure by checking username, '@' symbol, and domain suffix.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Validation & Errors). Copy the parameterized template or run the self-contained example.
- 1Category: Validation & Errors
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to validateEmail email
if email contains "@"
split email by "@" into parts
if length of parts is 2
userPart is first of parts
domainPart is last of parts
if length of userPart is greater than 0
if domainPart contains "."
return true
.
.
.
.
return false
.
to validateEmail email
if email contains "@"
split email by "@" into parts
if length of parts is 2
userPart is first of parts
domainPart is last of parts
if length of userPart is greater than 0
if domainPart contains "."
return true
.
.
.
.
return false
.
okEmail is validateEmail "dev@otter.org"
badEmail is validateEmail "invalid-email"
say "Check dev@otter.org:" okEmail
say "Check invalid-email:" badEmail
if okEmail is not true
fail with "validateEmail rejected valid email dev@otter.org"
.
if badEmail is not false
fail with "validateEmail accepted invalid email invalid-email"
.
Installation & Usage
otter snippet inspect val-email-check
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.