# hadid-validate
Lightweight input validation helpers for Hadid Web APIs and CLI apps.
## Installation
```sh
hadid add hadid-validate
```
## Usage
```hadid
import "hadid-validate" as v;
assert(v.is_valid_email("dev@dgtalhat.com"), "email");
assert(v.is_valid_username("digitalhat_01"), "username");
assert(v.in_range_i64(42, 1, 100), "range");
```
Tüm HADID Paketleri
hadid-validate
v0.1.0BLAKE2b-256Zero-dependency input validation helpers (email, username, length, range) for Hadid
# hadid-validate
Lightweight input validation helpers for Hadid Web APIs and CLI apps.
## Installation
```sh
hadid add hadid-validate
```
## Usage
```hadid
import "hadid-validate" as v;
assert(v.is_valid_email("dev@dgtalhat.com"), "email");
assert(v.is_valid_username("digitalhat_01"), "username");
assert(v.in_range_i64(42, 1, 100), "range");
```
[package]
name = "hadid-validate"
version = "0.1.0"
entry = "src/lib.had"
description = "Zero-dependency input validation helpers (email, username, length, range) for Hadid"
license = "MIT"
keywords = "validate,validation,email,forms,security"
repository = "https://github.com/DGTLHLHAT/hadid"
[dependencies]
// hadid-validate: Input validation helpers for Hadid (EN / TR)
fn is_non_empty(s: string): bool {
let n = length(s);
for (let i = 0; i < n; i = i + 1) {
let ch = s[i];
if (ch != 32) {
if (ch != 9) {
if (ch != 10) {
if (ch != 13) { return true; }
}
}
}
}
return false;
}
fn has_length_between(s: string, min_chars: i32, max_chars: i32): bool {
match (text_count(s)) {
Err(e) => { return false; }
Ok(cnt) => {
if (cnt < min_chars) { return false; }
if (cnt > max_chars) { return false; }
return true;
}
}
}
fn in_range_i64(val: i64, min_val: i64, max_val: i64): bool {
if (val < min_val) { return false; }
if (val > max_val) { return false; }
return true;
}
fn is_valid_username(u: string): bool {
let n = length(u);
if (n < 2) { return false; }
if (n > 32) { return false; }
let first = u[0];
bool first_ok = false;
if (first >= 97) {
if (first <= 122) { first_ok = true; }
}
if (first_ok == false) { return false; }
for (let i = 1; i < n; i = i + 1) {
let ch = u[i];
bool ok = false;
if (ch >= 97) {
if (ch <= 122) { ok = true; }
}
if (ch >= 48) {
if (ch <= 57) { ok = true; }
}
if (ch == 45) { ok = true; }
if (ch == 95) { ok = true; }
if (ok == false) { return false; }
}
return true;
}
fn is_valid_email(email: string): bool {
let n = length(email);
if (n < 5) { return false; }
if (n > 254) { return false; }
i32 at_pos = -1;
i32 dot_after_at = -1;
for (let i = 0; i < n; i = i + 1) {
let ch = email[i];
if (ch <= 32) { return false; }
if (ch > 126) { return false; }
if (ch == 64) {
if (at_pos >= 0) { return false; }
at_pos = i;
} else if (ch == 46) {
if (at_pos >= 0) { dot_after_at = i; }
}
}
if (at_pos < 1) { return false; }
if (dot_after_at <= at_pos + 1) { return false; }
if (dot_after_at >= n - 1) { return false; }
return true;
}
fn eposta_gecerli_mi(eposta: string): bool {
return is_valid_email(eposta);
}
fn kullanici_adi_gecerli_mi(ad: string): bool {
return is_valid_username(ad);
}
| Sürüm | Boyut | İndirme | BLAKE2b-256 | Durum |
|---|---|---|---|---|
| v0.1.0 | 3474 B | 1 | blake2b-256:7fe6469b4fea… | Aktif |