alphanumeric
This validator checks if a string has only alphanumeric characters.Basic Usage
import { alphanumeric } from "@prismane/core/validators"; console.log(alphanumeric("martinpetrov404")); // Will return null console.log(alphanumeric("Martin is cool")); // Will return an error`
useForm Hook Usage
function Demo() { const { handleSubmit, handleReset, register } = useForm({ fields: { username: { value: "", validators: { alphanumeric: (v: string) => alphanumeric(v), }, }, }, }); return ( <Form onSubmit={(e: any) => { handleSubmit(e, (v: any) => console.log(v)); }} onReset={() => handleReset()} maw={300} > <TextField placeholder="Enter username: " label="Username:" {...register("username")} /> <Button type="submit">Submit</Button> </Form> ); }
API
Parameters
Name | Type | Description |
---|---|---|
value | string | The value that will be validated. |
regExp | RegExp / undefined | Optional parameter that will change the regex that is used to validate the field |
fieldName | string / undefined | The name of the field. |