Skip to content

String Rules

📥 Import

js
import { stringRules } from 'suriform/rules'

📌 Overview

RuleDescriptionType
lengthMust be exactly N characterstext
regexMust match a regex pattern with flagstext
containsMust contain a specific substringtext
notContainsMust not contain a specific substringtext
oneOfMust match one of the allowed valuestext
notOneOfMust not match forbidden valuestext
betweenCharMust be between min and max characterstext
strongMust be a strong passwordtext

📝 Examples

html
<input type="text" length="5" />
<input type="text" regex="^[A-Za-z]+$,i" />
<input type="text" contains="abc" />
<input type="text" not-contains="xyz" />
<input type="text" one-of="yes,no,maybe" />
<input type="text" not-one-of="admin,root,test" />
<input type="text" between-char="3,10" />
<input type="password" strong />

▶️ Usage

html
<form id="signup">
  <label>
    Username:
    <input type="text" name="username" length="5" />
  </label>

  <label>
    Password:
    <input type="password" name="password" strong />
  </label>
</form>
js
import { watchform, defineRules } from 'suriform'
import { stringRules } from 'suriform/rules'

const form = document.querySelector('#signup')
watchform(form)
defineRules(stringRules)

Released under the MIT License.