validator.js for LWC
Provides form validation methods powered by validator.js in your lightning web component.
All methods of validator.js are available, and also length(str)
method that returns the emoji-aware number of string length is available.
Ported validator.js version
Besides validator.js, it also uses grapheme-splitter/next to count precise length of chars.
Available methods
Please see the validator.js document for methods.
In addition, this library provides length(str)
method to count precise string length with unicode + salogate pair (complex emojis) aware.
How to use
import validatorjs lwc component in your lwc by follow.
// default import
import validatorjs from 'c/validatorjs';
const isUrlFormat = validatorjs.isURL('https://google.com'); // true
const lengthOfChars = validatorjs.length('🏴'); // 1
// named import
import { isEmail, length } from 'c/validatorjs';
const isEmailFormat = isEmail('hello world'); // false
const lengthOfChars = length('😀'); // 1