Develop ultra fast with Prismane 🎉

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

NameTypeDescription
valuestringThe value that will be validated.
regExpRegExp / undefinedOptional parameter that will change the regex that is used to validate the field
fieldNamestring / undefinedThe name of the field.