colinaut / alpinejs-plugin-simple-validate

Simple Alpine form validation plugin
97 stars 4 forks source link

custom validation using Regex #10

Closed shopper360mst closed 1 year ago

shopper360mst commented 1 year ago

Hi is it possible to use custom validation rules using RegEx with this plugin? e.g. i have a different set of validation for Local ID Card number input for example.

colinaut commented 1 year ago

Yes. See example below for a field that allows any cheese except American cheese

<label for="cheese">Favorite Cheese *</label>
<input
type="text"
id="othercheese"
name="othercheese"
x-validate="!/american/i.test($el.value)"
data-error-msg="any cheese other than American"
/>