kilvalidate 1.0.70 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,15 +78,37 @@ Example: data-kilvish-file="pdf_1_4" restricts the selection to between 1 and 4
78
78
 
79
79
  Example: // limits to 1–4 files
80
80
 
81
- data-kilvish-password="8_20" for min and max pass
82
- Usage: To use these validation attributes, simply add the appropriate data-kilvish-* attribute to the tag in your HTML form. The validation will be applied automatically based on the specified rules.
83
81
 
84
- Example:
85
82
 
86
- Phone Number (7-20 digits):
87
- Username (letters and numbers):
88
83
 
89
- Password (letters, numbers, and special chars):
84
+ ## Password
85
+
86
+ ### Length & composition
87
+ - `data-kilvish-password="MIN_MAX"` – requires:
88
+ - at least one lowercase, one uppercase, one digit, one special character
89
+ - **no sequential runs** like `1234` or `abcd`
90
+ - Example: `data-kilvish-password="8_20"` ⇒ min 8, max 20.
91
+
92
+ ### Eye icon (show/hide)
93
+ An eye icon is auto-injected at the end of every password field and stays inside the input (works with/without `.input-group`).
94
+
95
+ **Attributes**
96
+ - `data-kileye-show` — behavior mode:
97
+ - `hold` *(default if omitted)*: press & hold to show; release/blur to hide
98
+ - `toggle`: click to show/hide
99
+ - `fix`: start visible; click to hide/show (no holding needed)
100
+ - `data-kileye-initial` — initial visibility: `on` | `off` *(default `off`; `fix` forces visible)*
101
+ - `data-kileye-color` — icon color (e.g., `#005555`)
102
+ - `data-kileye-false` — disable auto eye for this field
103
+
104
+ > The validator reserves right padding so text never sits under the icon, and the password meter + rules always render **below** the field.
105
+
106
+
107
+
108
+
109
+
110
+
111
+
90
112
 
91
113
  data-kilvish-amount // for setting amount or Price related validation
92
114
  Case 1: data-kilvish-amount="USD" Input: 2 → Auto-formats to 2.00 with cursor at 2|.00. Input: 25. → Allows further typing for decimal values, e.g., 25.5 or 25.55. Input: 25.555 → Automatically truncates to 25.55.
@@ -245,3 +267,299 @@ Author: Vasu Birla kilvishbirla@gmail.com
245
267
 
246
268
  You can include this script in your project via CDN:
247
269
  <script src="https://cdn.jsdelivr.net/npm/kilvalidate@1.0.62/kilvish.min.js"></script>
270
+
271
+
272
+ # KilValidate (Kil Validation)
273
+ A lightweight, drop‑in **form validation** CDN for web apps. Validates text, number, email, phone, files, amounts, dates, grouped dates, and **passwords with strength meter + eye icon**—all via **data‑attributes**. No initialization required.
274
+
275
+ > **CDN (latest)**
276
+ > ```html
277
+ > <script src="https://cdn.jsdelivr.net/npm/kilvalidate@1.0.62/kilvish.min.js"></script>
278
+ > ```
279
+
280
+ ---
281
+
282
+ ## Table of Contents
283
+ - [Why KilValidate](#why-kilvalidate)
284
+ - [Quick Start](#quick-start)
285
+ - [Global Behavior](#global-behavior)
286
+ - [Validation Attributes](#validation-attributes)
287
+ - [Numbers](#numbers)
288
+ - [Alphanumeric / Characters](#alphanumeric--characters)
289
+ - [Files](#files)
290
+ - [Amounts / Currency](#amounts--currency)
291
+ - [Dates](#dates)
292
+ - [Date Group (From/To)](#date-group-fromto)
293
+ - [Age](#age)
294
+ - [Password + Eye Icon](#password--eye-icon)
295
+ - [Notes](#notes)
296
+ - [Author](#author)
297
+
298
+ ---
299
+
300
+ ## Why KilValidate
301
+ - **Zero setup**: just add the CDN
302
+ - **Declarative**: use HTML `data-kilvish-*` attributes
303
+ - **UX friendly**: inline error slots, persistent labels/asterisks, no layout jumps
304
+ - **Robust**: works with Bootstrap `.input-group`, Select2, and dynamic DOM
305
+
306
+ ---
307
+
308
+ ## Quick Start
309
+ Add the CDN and then add attributes to your inputs. Raw HTML below will render as live inputs on your website.
310
+
311
+ ### Minimal form
312
+ <form id="demo-minimal" style="max-width:520px;padding:12px;border:1px solid #e5e7eb;border-radius:10px">
313
+ <label class="form-label" for="username">Username</label>
314
+ <input class="form-control" id="username" name="username" data-kilvish-char="mix" required placeholder="john_doe123">
315
+ <br>
316
+ <label class="form-label" for="contact">Phone</label>
317
+ <input class="form-control" id="contact" name="contact" type="tel" required placeholder="+1 555 123 4567">
318
+ <br>
319
+ <label class="form-label" for="pwd">Password</label>
320
+ <input class="form-control" id="pwd" name="password" type="password" data-kilvish-password="12_64" data-kileye-show="toggle" data-kileye-color="#005555" required placeholder="Strong password">
321
+ <br>
322
+ <button type="submit" class="btn btn-primary">Submit</button>
323
+ </form>
324
+
325
+ ---
326
+
327
+ ## Global Behavior
328
+ - Required fields get a red asterisk automatically.
329
+ - Errors render **under** the correct control (incl. `.input-group` and Select2).
330
+ - Password **strength meter + rule list** render **below** the field.
331
+ - Phone (`type="tel"` or `data-kilvish-tel`) avoids false positives (country code only).
332
+
333
+ ---
334
+
335
+ ## Validation Attributes
336
+
337
+ ### Numbers
338
+ #### Numbers only
339
+ - **Attribute:** `data-kilvish-num="yes"`
340
+ - Ensures only digits.
341
+
342
+ <form style="max-width:520px">
343
+ <label for="numonly">Numbers Only</label>
344
+ <input id="numonly" class="form-control" data-kilvish-num="yes" required placeholder="123456">
345
+ </form>
346
+
347
+ #### Numbers with length limits
348
+ - **Attribute:** `data-kilvish-num="_7_20"`
349
+ - Only digits, length **7–20**.
350
+
351
+ <form style="max-width:520px">
352
+ <label for="numlen">Numbers (7–20)</label>
353
+ <input id="numlen" class="form-control" data-kilvish-num="_7_20" required placeholder="9876543">
354
+ </form>
355
+
356
+ ---
357
+
358
+ ### Alphanumeric / Characters
359
+ #### Mix (letters+numbers)
360
+ - **Attribute:** `data-kilvish-char="mix"`
361
+
362
+ <form style="max-width:520px">
363
+ <label for="uname">Username (letters & numbers)</label>
364
+ <input id="uname" class="form-control" data-kilvish-char="mix" required placeholder="john123">
365
+ </form>
366
+
367
+ #### Mix with specific specials
368
+ - **Attribute:** `data-kilvish-char="mix_%_$"`
369
+
370
+ <form style="max-width:520px">
371
+ <label for="mixspec">Username (allow %, _, $)</label>
372
+ <input id="mixspec" class="form-control" data-kilvish-char="mix_%_$" required placeholder="john_doe%">
373
+ </form>
374
+
375
+ #### Address‑friendly (space, dash, comma)
376
+ - **Attribute:** `data-kilvish-char="mix_ ,-_”`
377
+
378
+ <form style="max-width:520px">
379
+ <label for="addr">Address</label>
380
+ <input id="addr" class="form-control" data-kilvish-char="mix_ ,-_" required placeholder="221B Baker Street, London">
381
+ </form>
382
+
383
+ #### Letters only
384
+ - **Attribute:** `data-kilvish-char="Yes"`
385
+
386
+ <form style="max-width:520px">
387
+ <label for="fname">First Name (letters only)</label>
388
+ <input id="fname" class="form-control" data-kilvish-char="Yes" required placeholder="John">
389
+ </form>
390
+
391
+ #### Letters + specific specials
392
+ - **Attribute:** `data-kilvish-char="Yes_%_$"`
393
+
394
+ <form style="max-width:520px">
395
+ <label for="brand">Brand (letters + %,_,$)</label>
396
+ <input id="brand" class="form-control" data-kilvish-char="Yes_%_$" required placeholder="ACME_Pro%">
397
+ </form>
398
+
399
+ ---
400
+
401
+ ### Files
402
+ Use `data-kilvish-file` on `<input type="file">`.
403
+
404
+ - `image` (default): images only
405
+ - `image_MIN_MAX`: min/max count (e.g., `image_1_3`)
406
+ - `doc`: PDF, Word, Excel
407
+ - `doc_MIN_MAX` (e.g., `doc_1_4`)
408
+ - `pdf`: only PDF
409
+ - `pdf_MIN_MAX`
410
+ - `mix`: images + docs
411
+ - `only_pdf_image`: PDFs + images
412
+ - `only_doc_image`: DOC‑related + images
413
+
414
+ <form style="max-width:520px">
415
+ <label for="fileimg">Images (1–3)</label>
416
+ <input id="fileimg" class="form-control" type="file" data-kilvish-file="image_1_3" multiple>
417
+ </form>
418
+
419
+ <form style="max-width:520px">
420
+ <label for="filedoc">Documents (1–4)</label>
421
+ <input id="filedoc" class="form-control" type="file" data-kilvish-file="doc_1_4" multiple>
422
+ </form>
423
+
424
+ ---
425
+
426
+ ### Amounts / Currency
427
+ Use `data-kilvish-amount="CUR[_MIN_MAX]"`
428
+
429
+ - `USD` → formats to 2 decimals (e.g., `2` → `2.00`).
430
+ - `USD_200_1000` → min/max enforced with inline messages.
431
+
432
+ <form style="max-width:520px">
433
+ <label for="amt1">Amount (USD)</label>
434
+ <input id="amt1" class="form-control" data-kilvish-amount="USD" placeholder="25 or 25.50">
435
+ </form>
436
+
437
+ <form style="max-width:520px">
438
+ <label for="amt2">Amount (USD 200–1000)</label>
439
+ <input id="amt2" class="form-control" data-kilvish-amount="USD_200_1000" placeholder="250">
440
+ </form>
441
+
442
+ ---
443
+
444
+ ### Dates
445
+ Attach `data-kilvish-date` to `<input type="date">` or `<input type="month">`.
446
+
447
+ - Age window: `_18_60` (between 18 and 60)
448
+ - **Future**: `future`, `today_future`, `30_days_future`, `2_years_future`, `2_years_after`
449
+ - **Past**: `past`, `10_years_past`, `2_years_before`
450
+ - **Ranges**: `Between_2000_2010`, `from_2023`, `till_2025`
451
+ - **Specific**: `not_today`, `weekday`, `weekend`, `first_of_month`, `last_of_month`, `exact_21`
452
+
453
+ <form style="max-width:520px">
454
+ <label for="dob">DOB (18–60)</label>
455
+ <input id="dob" class="form-control" type="date" data-kilvish-date="_18_60" required>
456
+ </form>
457
+
458
+ <form style="max-width:520px">
459
+ <label for="future">Future date (next 30 days)</label>
460
+ <input id="future" class="form-control" type="date" data-kilvish-date="30_days_future">
461
+ </form>
462
+
463
+ <form style="max-width:520px">
464
+ <label for="wk">Weekday only</label>
465
+ <input id="wk" class="form-control" type="date" data-kilvish-date="weekday">
466
+ </form>
467
+
468
+ > `leap_year` & combined multi‑conditions like `future_weekday` are **reserved** / not implemented yet.
469
+
470
+ ---
471
+
472
+ ### Date Group (From/To)
473
+ Link two fields so **From ≤ To** (or months).
474
+
475
+ - **Format:** `data-kilvish-dategroup="EMP_1"` and `data-kilvish-dategroup="EMP_2"`
476
+ - Optional labels: `data-kilvish-date_name="From"` / `"To"`
477
+
478
+ <form style="max-width:520px">
479
+ <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
480
+ <div>
481
+ <label for="empFrom">Employment From</label>
482
+ <input id="empFrom" class="form-control" type="month" data-kilvish-dategroup="EMP_1" data-kilvish-date_name="From" required>
483
+ </div>
484
+ <div>
485
+ <label for="empTo">Employment To</label>
486
+ <input id="empTo" class="form-control" type="month" data-kilvish-dategroup="EMP_2" data-kilvish-date_name="To" required>
487
+ </div>
488
+ </div>
489
+ </form>
490
+
491
+ ---
492
+
493
+ ### Age
494
+ Validate a plain age number.
495
+
496
+ - **Attribute:** `data-kilvish-age="value"` → exact age
497
+ - **Attribute:** `data-kilvish-age="min_max"` → range
498
+
499
+ <form style="max-width:520px">
500
+ <label for="ageExact">Exact age 18</label>
501
+ <input id="ageExact" class="form-control" name="age" data-kilvish-age="18" placeholder="18">
502
+ </form>
503
+
504
+ <form style="max-width:520px">
505
+ <label for="ageRange">Age 18–60</label>
506
+ <input id="ageRange" class="form-control" name="age" data-kilvish-age="18_60" placeholder="e.g., 25">
507
+ </form>
508
+
509
+ ---
510
+
511
+ ## Password + Eye Icon
512
+
513
+ ### Length & composition
514
+ - `data-kilvish-password="MIN_MAX"` – requires:
515
+ - at least one lowercase, one uppercase, one digit, one special character
516
+ - **no sequential runs** like `1234` or `abcd`
517
+ - Example: `data-kilvish-password="8_20"` ⇒ min 8, max 20.
518
+
519
+ ### Eye icon (show/hide)
520
+ An eye icon is auto-injected at the end of every password field and stays inside the input (works with/without `.input-group`).
521
+
522
+ **Attributes**
523
+ - `data-kileye-show` — behavior:
524
+ - `hold` *(default if omitted)*: press & hold to show; release/blur to hide
525
+ - `toggle`: click to show/hide
526
+ - `fix`: start visible; click to hide/show (no holding needed)
527
+ - `data-kileye-initial` — `on` | `off` *(default `off`; `fix` forces visible)*
528
+ - `data-kileye-color` — icon color (e.g., `#005555`)
529
+ - `data-kileye-false` — disable auto eye for this field
530
+
531
+ <form style="max-width:520px">
532
+ <label for="pass1">Password (toggle eye)</label>
533
+ <input id="pass1" class="form-control" type="password" data-kilvish-password="12_64" data-kileye-show="toggle" data-kileye-color="#005555" placeholder="Strong password">
534
+ </form>
535
+
536
+ <form style="max-width:520px">
537
+ <label for="pass2">Password (fixed visible)</label>
538
+ <input id="pass2" class="form-control" type="password" data-kilvish-password="12_64" data-kileye-show="fix" placeholder="Visible until you click eye">
539
+ </form>
540
+
541
+ <form style="max-width:520px">
542
+ <label for="pass3">Confirm Password (hold)</label>
543
+ <div class="input-group">
544
+ <span class="input-group-text"><i class="ti ti-key"></i></span>
545
+ <input id="pass3" class="form-control" type="password" data-kilvish-password="8_20" placeholder="Re-enter password">
546
+ </div>
547
+ </form>
548
+
549
+ > The password strength meter and rule list render **below** the field and update in real time.
550
+
551
+ ---
552
+
553
+ ## Notes
554
+ - Works with plain HTML or frameworks (EJS/Blade/etc.).
555
+ - Error slots are **persistent nodes** (no layout shift).
556
+ - Add `data-ignore-kilvish="Yes"` to opt a field out of realtime checks.
557
+ - Required stars are normalized & auto‑deduped.
558
+
559
+ ---
560
+
561
+ ## Author
562
+ **Vasu Birla (Kilvish)**
563
+ <kilvishbirla@gmail.com>
564
+
565
+
@@ -0,0 +1,68 @@
1
+ # KilValidate for Next.js (Client Only)
2
+
3
+ KilValidate is a DOM-based validator. It must run in the browser and is intended for client components. It does not use React state or form libraries internally; it reads and writes the DOM (error nodes, borders, etc.).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i kilvalidate
9
+ ```
10
+
11
+ ## Quick Start (App Router)
12
+
13
+ ```js
14
+ 'use client';
15
+ import React from 'react';
16
+ import { useKilvalidate } from 'kilvalidate/kilnextvalidation-react';
17
+
18
+ export default function Page() {
19
+ useKilvalidate();
20
+
21
+ return (
22
+ <form id="signup">
23
+ <input name="firstname" required />
24
+ <button type="submit">Submit</button>
25
+ </form>
26
+ );
27
+ }
28
+ ```
29
+
30
+ ## Quick Start (Pages Router)
31
+
32
+ ```js
33
+ import React, { useRef } from 'react';
34
+ import { useKilvalidate } from 'kilvalidate/kilnextvalidation-react';
35
+
36
+ export default function Page() {
37
+ const formRef = useRef(null);
38
+ useKilvalidate({ form: formRef });
39
+
40
+ return (
41
+ <form id="signup" ref={formRef}>
42
+ <input name="firstname" required />
43
+ <button type="submit">Submit</button>
44
+ </form>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ## React Form Libraries
50
+
51
+ KilValidate can be used alongside form libraries, but it will not update React state. You can run it inside your submit handler to block submit:
52
+
53
+ ```js
54
+ import kilvalidate from 'kilvalidate';
55
+
56
+ function onSubmit(e) {
57
+ if (!kilvalidate.validateForm('#signup', e)) return;
58
+ // proceed with your submit
59
+ }
60
+ ```
61
+
62
+ If you need fully state-driven validation (errors as JS objects), the validator would need to be refactored to return structured error data instead of writing to the DOM. I can add that as a separate module if you want.
63
+
64
+ ## Notes
65
+
66
+ - Use only in client components.
67
+ - It injects CSS and writes error elements directly to the DOM.
68
+ - You can opt out per field with `data-ignore-kilvish`.
@@ -0,0 +1,42 @@
1
+ 'use client';
2
+
3
+ const React = require('react');
4
+ const { useEffect } = React;
5
+ const kilvalidateModule = require('./kilnextvalidation.js');
6
+
7
+ function getKilvalidate() {
8
+ return kilvalidateModule && kilvalidateModule.default ? kilvalidateModule.default : kilvalidateModule;
9
+ }
10
+
11
+ function resolveFormTarget(target) {
12
+ if (!target) return null;
13
+ if (target.current) return target.current;
14
+ return target;
15
+ }
16
+
17
+ function useKilvalidate(options = {}) {
18
+ const { form, auto = true } = options;
19
+
20
+ useEffect(() => {
21
+ if (!auto) return;
22
+ if (typeof window === 'undefined') return;
23
+ const api = getKilvalidate();
24
+ if (!api) return;
25
+
26
+ const formTarget = resolveFormTarget(form);
27
+ if (formTarget) {
28
+ api.addRealTimeValidation(formTarget);
29
+ api.attachInputEvents();
30
+ api.addAsteriskToRequiredFields();
31
+ api.addValidateFormToSubmitButtons();
32
+ api.initPasswordStrengthMeter();
33
+ } else {
34
+ api.init();
35
+ }
36
+ }, [form, auto]);
37
+ }
38
+
39
+ module.exports = {
40
+ useKilvalidate,
41
+ getKilvalidate
42
+ };